Testing with Spring, Guice, JMock, Mockito... How to integrate


News: Testing with Spring, Guice, JMock, Mockito... How to integrate

  1. 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, ... 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: @GuiceContext(ClusterModule.class) public final class ClusterNodeListenerTest extends AbstractMycilaTestNGTest { @Inject ClusterFactory factory; @Mock ClusterNodeListener listener; @Mock @Bind(scope = Singleton.class) ClusterService service; @Test public void test_ClusterNodeListener() throws Exception { ClusterState agent1 = factory.createClusterState("states"); agent1.addListener(listener); ClusterState agent2 = factory.createClusterState("testatoo-states"); Thread.sleep(4000); agent2.close(); Thread.sleep(4000); agent1.close(); 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: * Maven License Plugin: A Maven 2 plugin to manage your license headers in source files: http://code.google.com/p/maven-license-plugin/ * XML Tool: Create, parse and navigate in XML document through a very intuitive and simple API using Fluent Interface: http://code.google.com/p/xmltool/ * Mycila Plugin Framework: A simple but powerful plugin framework to add extensiblity into your application: http://code.mycila.com/wiki/MycilaPlugin * Maven Deployer GUI: A Graphic tool to help deploying Maven Artifact: http://code.mycila.com/wiki/MavenDeployer Mathieu
  2. I've used Unitils a little bit and have been pretty pleased with what it provides. I'm not that familiar with what AtUnit brings to the table but this looks pretty promising. I'll try to check it out soon, thanks for the heads up.
  3. Hi, Yes i know Unitils. It provides an already integrated stack for Spring/Easymck/DbUnit. But Mycila and Unitils differs in the sense that Unitils is a testing framework, based on Junit / TstNG. I think you cannot replace Spring by Guice, or use Mockito instead of Easymock. So you must use what it provides, and if a day you ant to change the mock framework in a project, or switch to Guice, to have to also change your testing framework or use another one. Mycila is much more an integrator of testing framework. It is agnostic from what technology you use thanks to its plugin architecture. Thus, if you want to use Guice + Mockito, simply drop in the classpath the two plugins. You want to add Spring support ? Just put the Spring plugin jar on your classpath ;) Thus, anyone can build its own plugins and use any technology he wants. Also, what is interesting is that with Mycila, you could write a Unitils plugins. I.E. to simplify the DbUnit setup or use more annotations to automate things, and inject in your test the DbUnit tester in example, to avoid extending a BaseDAOTest or UnitilsJUnit4 class . Cheers, Mathieu.