Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
Description
I noticed that there is a test class PrintingVisitor implements production interface SchemaVisitor to assist testing CloningVisitor. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.
Current Implementation
- PrintingVisitor implements SchemaVisitor and implements methods.
- In test case, the child test class is used to assit testing by logging out method excution information.
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.
Motivation
- Decouple test class PrintingVisitor from production interface SchemaVisitor.
- Remove the redundant test child class PrintingVisitor
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.