InfoQ

News

Mocking for Java and Flex

Posted by Craig Wickesser on Jul 07, 2009

Community
Java
Topics
Release ,
Unit Testing ,
Rich Internet Apps
Tags
Java SE ,
TDD ,
mockito-flex ,
Mockito ,
mockito-python ,
Python ,
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.

No comments

Watch Thread Reply

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.