InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Mocking for Java and Flex

Posted by Craig Wickesser on Jul 07, 2009

Sections
Process & Practices,
Development,
Operations & Infrastructure
Topics
Unit Testing ,
Java ,
Release ,
Rich Internet Apps
Tags
mockito-flex ,
Java SE ,
Flex ,
mockito-python ,
TDD ,
Python ,
Mockito

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

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.

Architecting Visa for Massive Scale and Continuous Innovation

John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.

Max Protect: Scalability and Caching at ESPN.com

Sean Comerford unveils ESPN.com’s architecture, what components are used and why, and the current changes the website goes through.

The Seven Deadly Sins of Enterprise Agile Adoption

Are there repeated patterns of failure on Enterprise Agile Enablement efforts? Sanjiv and Arlen discuss Seven Deadly Sins to avoid when adopting Agile in an enterprise.

Questions for an Enterprise Architect

Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?

Wrap Your SQL Head Around Riak MapReduce

Sean Cribbs explains what Map-Reduce and Riak are, why and how to use Map-Reduce with Riak, and how to convert SQL queries into their Map-Reduce equivalents.

Polyglot Persistence for Java Developers - Moving Out of the Relational Comfort Zone

Chris Richardson shows how he ported a relational database to three NoSQL data stores: Redis, Cassandra and MongoDB.

The Golden Circle – Why How What

Jean Tabaka challenges the audience to reflect on what Agile practices they are employing, how they are using them, ending with the questions “Why have their organization chosen to go Agile?