Mocking for Java and Flex
Recently version 1.8 (rc2) of the Mockito framework was released and InfoQ had the chance to talk with the project owner, Szczepan Faber.
Note, although 1.8 hasn't had a final release Szczepan promises it's going to be equivalent to the 1.8 RC2 release and is expected to be available any day.
InfoQ: What should developers be looking forward to in the 1.8 release?
There are no major changes in 1.8 but the release contains a couple of handy features that should make life of a developer easier. There is an API for capturing arguments for further assertions. It makes verifying method parameters very effective.
We decided to add aliases for stubbing API to integrate smoothly with behavior-driven development style of writing unit tests. It means your //given //when //then comments in tests will now read very nicely with new given().willReturn() stubbing alias.
This release of Mockito finally earned 'real' partial mocks. We debated quite a long time if this is a valid feature but eventually we found practical use cases. The full feature list is available here: http://code.google.com/p/mockito/wiki/ReleaseNotes
InfoQ: What's on the roadmap after 1.8?
I thought the work on Mockito will finish with 1.0 but somehow there is always a flow of new ideas and improvements. Many thanks to users who share their feedback and suggestion via the mockito mailing list. It's hard to name a specific feature for future releases. Surely, we will still try to keep the API simple. We will continue improving failure feedback so that the TDD cycles are fast & smooth.
InfoQ: Recently a new project was created named Mockito for Flex, is this an official sub-project for Mockito?
It's not a fork because it's a totally different language. I guess you can say it's official collaboration because me and Krzysztof Karczmarczyk paired on the implementation of mockito-flex. I think Krzysztof updated the information on the main page of mockito-flex.
InfoQ: Can you provide some good resources for really getting into Mockito and finding how to use the expansive set of features?
Any general tutorial on mock objects is good to grasp the concepts. Brett Schuchert wrote a tutorial on Mockito. As far as specific features are concerned, all the documentation, including working code examples lives in the javadocs. The reason we keep entire documentation in the javadocs is that we want it to be consistent with what is presented on mockito.org web page. Also, it's helpful if all the documentation is available straight from IDE, even if one works offline.
Good starting point to learn about the features is a javadoc for Mockito class.
Currently, mockito-flex is at version 1.0 and provides the follow capabilities:
- Support for verification of method calls and properties access
- Support for stubbing of method calls and properties access
- Support for basic matchers and extensible API for creating new matchers
- Integration with flex unit
- Based on asmock-0.3 (for bytecode generation and lowlevel execution handling)
Lastly, if you are a Python developer have a look at mockito-python.
Yoni Goldberg Oct 30, 2014
Dmytro Svarytsevych Oct 30, 2014