Running Tests

Esko Luontola edited this page Feb 16, 2014 · 13 revisions

sbt users

The sbt-jumi plugin lets you run Jumi tests using the sbt build tool.

Everyone else

Until there is proper tool support from IDEs and build tools, you can run tests with Jumi by using the JumiBootstrap helper class which runs tests using the same classpath as the process which calls JumiBootstrap.

First you need to add a test-scope dependency to jumi-launcher into your project.

Next create a main method, as shown below, to launch Jumi. Alternatively you may wrap the bootstrap code in a JUnit test, if that makes it easier for you to run the tests in your IDE or build tool.

import fi.jumi.launcher.JumiBootstrap;

public class JumiSuite {

    public static void main(String[] args) throws Exception {
        JumiBootstrap bootstrap = new JumiBootstrap();
        bootstrap.suite
                .addJvmOptions("-ea")
                .setIncludedTestsPattern("glob:com/example/**Test.class"); // uses Java 7 glob patterns
        bootstrap
                //.enableDebugMode() // shows Jumi's internal messaging; can be useful for testing framework developers
                //.setPassingTestsVisible(true) // shows full output from all tests, instead of just failing tests
                .runSuite();
    }
}

The JumiBootstrap class has also a main method, so you can invoke it directly as a Java application by giving the names of the test classes as command line arguments. It has also some more fine-grained methods for customizing the way how the tests are run, and to help write your own bootstrapper.

If you are implementing Jumi support for an IDE or build tool, you might be more interested in these slightly older examples (especially the Bootstrap class) of how to run tests with Jumi without the complexity of JumiBootstrap.