Over the past few months I’ve spent a fair amount of time with the Spring 2.5 annotation-based integration test support and have by and large been impressed. The combination of the @ContextConfiguration and @Transactional annotations with Autowiring makes most integration tests easy to write and read. Add in the support for caching of an ApplicationContext once it’s been loaded once and the benefit to cost ratio looks much rosier for most integration tests.
However, I recently tried to write a regression test against the output of a view (in this case a Velocity template, but it’s a general issue) and came across an exception:
Recently I’ve spent a fair bit of time moving some older unit tests from JUnit3 with JMock1 to JUnit4 with Mockito. It’s been a real pleasure to see how much more clearly the tests read afterwards and while the benefits would not have been so marked if I’d been moving the test from Easymock, I’m clear there would have been a noticable improvement.
Mockito has many helpful little touches. The @Mock annotation not only reduces boilerplate, but also clearly identifies mocks in member variable definitions. The well thought out stack traces present failure information as clearly as possible. However, where it really stands out from other mocking frameworks is that it makes you think more clearly about what it is you’re actually testing and then express that intent in the test.