Skip to content
Dynamically run all JUnit Tests in Directories or on the Classpath
Find file
Latest commit a1e9670 Dec 1, 2015 @cschoell Merge pull request #7 from creinig/master
Added support for scanning multiple directories


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.



To get your started just annotate a class with


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


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.

Other Options

Available with Version 0.2.5:

You may use the Annotation @Directories to search for test classes in multiple directories.

@Directories({"bin", "target/classes"})
@Directories({"src/test/java", "src/test/generated"})

Available with Version 0.2.3:

You may use the Annotation @Sort to sort the tests by TestName or Randomize them.

@Sort(SortBy.TESTNAME) //sort by Name of Test
@Sort(SortBy.RANDOM) //run Tests in a random order
@Sort(value = SortBy.CUSTOM, customSort=<<class implementing TestSort>>.class)


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

public class IntegrationSuite implements TestClassFilter {

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

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


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



Copyright © 2013 Christof Schoell

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

You may obtain a copy of this license under

Something went wrong with that request. Please try again.