Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / Java
Tip/Trick

Roger Rabbit - JUnit Tests Runner Across Multiple Projects

,
Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
29 Nov 2013CPOL2 min read 13.2K   193   3  
Running JUnit tests across multiple projects

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...

Image 1

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:

Java
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.

Image 2

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.

Image 3

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:

XML
<dependencies>
  <dependency>
    <groupId>cpsuite</groupId>
    <artifactId>cpsuite</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
  </dependency>
</dependencies>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --