You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Xiao Wang (Jira)" <ji...@apache.org> on 2021/09/19 17:13:00 UTC
[jira] [Created] (AVRO-3211) Refactor PrintingVisitor to improve
test design
Xiao Wang created AVRO-3211:
-------------------------------
Summary: Refactor PrintingVisitor to improve test design
Key: AVRO-3211
URL: https://issues.apache.org/jira/browse/AVRO-3211
Project: Apache Avro
Issue Type: Improvement
Reporter: Xiao Wang
h3. Description
I noticed that there is a test class [PrintingVisitor|https://github.com/apache/avro/blob/42822886c28ea74a744abb7e7a80a942c540faa5/lang/java/compiler/src/test/java/org/apache/avro/compiler/schema/TestSchemas.java#L41] implements production interface [SchemaVisitor|https://github.com/apache/avro/blob/42822886c28ea74a744abb7e7a80a942c540faa5/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/SchemaVisitor.java#L22] to assist testing [CloningVisitor|https://github.com/apache/avro/blob/42822886c28ea74a744abb7e7a80a942c540faa5/lang/java/compiler/src/main/java/org/apache/avro/compiler/schema/CloningVisitor.java#L33]. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.
h3. Current Implementation
* {{PrintingVisitor}} implements {{SchemaVisitor}} and overrides methods to call super methods defined in parent class.
* In test case, the child test class is used to assit testing by logging out method excution information.
h3. Proposed Implementation
* Replace {{PrintingVisitor}} with a mocking object created by Mockito.
* Use method stub to control the behavior of the mocking object and logging information.
* Create a method to return the mocking object for reusing.
h3. Motivation
* Decouple test class {{PrintingVisitor}} from production interface {{SchemaVisitor}}.
* Remove the redundant test child class {{PrintingVisitor}}
h3. More Thought
* If we only use {{PrintingVisitor}} to log out information, we can actually get rid of PrintingVisitor and spy CloningVisitor, then use Mockito.verify() to verify method execution times and order based on the given Schema.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)