Dynamically run all JUnit Tests in Directories or on the Classpath
Pull request Compare This branch is 51 commits behind cschoell:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
README.rdoc
pom.xml

README.rdoc

JUnit DynamicSuite

The JUnit DynamicSuite is a library used to create a dynamic Suite of JUnit Tests from a directory. The Unit Tests can be filtered dynamically by annotating the Suite with a filter.

Dependencies

Usage

To get your started just annotate a class with

@RunWith(DynamicSuite.class)
@Filter(DefaultFilter.class)
@Directory

This will run all Tests ending with “Test” in the directory

target/test-classes

which is specified as default in the Directory Annotation.

Instead of using @Directory you might aswell use

@ClassPath(includeJars = true)

which scans the ClassPath for test classes. The Parameter includeJars allows you to control wether to scan the jars on the classpath (default false - only directories).

To create a custom filter you may either implement the interface TestClassFilter or extend the DefaultFilter.

Example

You can let the dynamic suite directly implement the TestClassFilter interface as shown below.

@RunWith(DynamicSuite.class)
@Filter(IntegrationSuite.class)
@Directory("test/out")
public class IntegrationSuite implements TestDirectoryFilter {

    @Override
    public boolean include(String className) {
        return className.endsWith("ITCase");
    }

    @Override
    public boolean include(Class cls) {
        return cls.getAnnotation(Ignore.class) == null;
    }
}

Installation

Either include the library directly by downloading it here from github or include it in Maven (from Maven Central Repository):

<dependency>
    <groupId>com.github.cschoell</groupId>
    <artifactId>junit-dynamicsuite</artifactId>
    <version>0.2.1</version>
    <scope>test</scope>
</dependency>

Copyright

Copyright © 2011 Christof Schoell

The files in this archive are released under the Apache 2.0 license.

You may obtain a copy of this license under www.apache.org/licenses/LICENSE-2.0