[ 
https://issues.apache.org/jira/browse/AVRO-3211?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Xiao Wang updated AVRO-3211:
----------------------------
    Description: 
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 method.
 * 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.

  was:
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.


> 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
>            Priority: Minor
>
> 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 method.
>  * 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)

Reply via email to