Introduction
Roger Rabbit is a sample project that demonstrates how to use the open source classpath suite for running JUnit tests across multiple projects.
Background
Imagine you are working on a product which consists of many Java projects. Each project has its own test suite, or even projects which their whole purpose is testing. When you make a change, you probably would like to run all relevant tests which can belong to many different projects. The naive way is to go project by project and run its test suite. This is, of course, exhausting...
Another option is to commit the change and let the CI do it for you, but this way the feedback is not immediate (you have to wait for compilation, other related jobs, etc.) and if the tests you want to run are unit tests - it is very fast and convenient to run those tests locally and get immediate feedback.
Roger Rabbit allows you to run all tests with one click.
How the Magic Works
Roger Rabbit is a project which has a dependency to classpath suite and to all projects that contain tests, we want to run (using project dependency, but you can also use Maven).
It has a single class file under utest folder which looks like this:
package com.rogerrabbit;
import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.runner.RunWith;
@RunWith(ClasspathSuite.class)
public class TestRunner {}
Now, whenever you want to run all junit tests that Roger Rabbit depends on, all you have to do is run TestRunner
class.
Points of Interest
Coverage
Using Roger Rabbit, you can easily measure your entire code coverage. If you are familiar with Eclipse coverage plugin, it can be used when running TestRunner
class and by that, it would check how much your code is covered.
Eclipse Launcher
If you're using Eclipse, we have added a roger-rabbit.launch file which adds to Run As and Debug As toolbar buttons a JUnit launcher.
Maven
If you’re using Maven, the library can be referenced like this:
<dependencies>
<dependency>
<groupId>cpsuite</groupId>
<artifactId>cpsuite</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
</dependencies>