Over a million developers have joined DZone.

Unit Testing with Spring, Guice, JMock, Easymock, Mockito...

DZone's Guide to

Unit Testing with Spring, Guice, JMock, Easymock, Mockito...

Free Resource

When you write unit tests, as the project grows to end up by using many technologies such as Jmock (or another mock framework like Mockito), DbUnit, Selenium, your favorite IOC, ... Integration of these technologies requires you to write pleinty of time the same code to setup a context, prepare your test, inject, ...

Mycila Testing Framework is an integration library that take care of all this code so that the developer can focuse on his tests. It currently has plugins for Guice 1 & 2, Spring, JMock, EasyMock, Mockito, AtUnit and we plan to add support for DbUnit, JGroups, JMS, JMX, Selenium, and others ...

Existing plugins are based on annotations and enables you to

  • quickly create mocks,
  • create bindings and bean definitions
  • add them to the application context (or injector for Guice), supporting overriding of existing beans,
  • inject services, ...

Mycila is based on a plugin architecture. Writing new plugins is trivial: anyone can contribute and write its own plugin and use it directly just by putting a jar on the claspath. The library supports any testing framework thnaks to its design (tested on TestNG and Junit). It works by enhancing your test from the plugins discovered on the classpath. As a result, you end up with a concise test.

Here is an example of unit test, using Guice 2 and Mockito:

public final class ClusterNodeListenerTest extends AbstractMycilaTestNGTest {
ClusterFactory factory;
ClusterNodeListener listener;
@Bind(scope = Singleton.class)
ClusterService service;
public void test_ClusterNodeListener() throws Exception {
ClusterState agent1 = factory.createClusterState("states");
ClusterState agent2 = factory.createClusterState("testatoo-states");
verify(listener, times(1)).onJoin(any(UUID.class));
verify(listener, times(1)).onLeave(any(UUID.class));

The project is located at http://code.mycila.com/wiki/MycilaTesting.
Feel free to post your comment, issues, contributions :)

Also have a look at other useful projects we develop:




Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}