JUnit Platform Suite provides declarative test suite framework with annotations for creating and configuring comprehensive test suites on the JUnit 5 platform.
—
Comprehensive test selection capabilities providing flexible methods to specify which tests to include in a suite through classes, packages, methods, files, directories, URIs, modules, and classpath resources.
Specifies classes to select for the test suite, supporting both direct class references and string-based class names.
/**
* Specifies classes to select for test suite execution.
* Supports both direct class references and fully qualified class names.
* Can combine both approaches in a single annotation.
*
* @since 1.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = MAINTAINED)
public @interface SelectClasses {
/**
* One or more classes to select for test execution.
* @return array of classes to select
*/
Class<?>[] value() default {};
/**
* Fully qualified class names to select.
* Useful for private/package-private classes not directly referenceable.
* @return array of fully qualified class names
* @since 1.10
*/
@API(status = EXPERIMENTAL, since = "1.10")
String[] names() default {};
}Usage Examples:
// Direct class references
@Suite
@SelectClasses({UserTest.class, ProductTest.class, OrderTest.class})
class BusinessSuite {
}
// String-based class names
@Suite
@SelectClasses(names = {
"com.example.internal.PrivateTest",
"com.example.util.PackagePrivateTest"
})
class InternalTestSuite {
}
// Combined approach
@Suite
@SelectClasses(
value = {UserTest.class, ProductTest.class},
names = {"com.example.internal.PrivateUserTest"}
)
class CombinedClassSuite {
}Specifies packages to select for test suite execution, enabling package-based test discovery.
/**
* Specifies packages to select for test suite execution.
* Discovers all classes within specified packages according to
* configured include/exclude filters.
*
* @since 1.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = MAINTAINED)
public @interface SelectPackages {
/**
* One or more fully qualified package names to select.
* @return array of package names to include in test discovery
*/
String[] value();
}Usage Examples:
// Single package selection
@Suite
@SelectPackages("com.example.integration")
class IntegrationSuite {
}
// Multiple package selection
@Suite
@SelectPackages({
"com.example.unit",
"com.example.integration",
"com.example.e2e"
})
class ComprehensiveSuite {
}
// Package selection with filtering
@Suite
@SelectPackages("com.example")
@IncludeClassNamePatterns(".*Test")
@ExcludeClassNamePatterns(".*AbstractTest")
class FilteredPackageSuite {
}Specifies individual methods to select for test suite execution with flexible method identification options.
/**
* Specifies a method to select for test suite execution.
* Supports multiple identification strategies: fully qualified names,
* class/method combinations, and parameter type specifications.
*
* @since 1.10
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@Repeatable(SelectMethods.class)
@API(status = EXPERIMENTAL, since = "1.10")
public @interface SelectMethod {
/**
* Fully qualified method name in format:
* [fully.qualified.ClassName]#[methodName]
* [fully.qualified.ClassName]#[methodName](parameter type list)
* Cannot be combined with other attributes.
* @return fully qualified method identifier
*/
String value() default "";
/**
* Class containing the method to select.
* Mutually exclusive with typeName().
* @return class containing the target method
*/
Class<?> type() default Class.class;
/**
* Fully qualified class name containing the method.
* Alternative to type() for classes not directly referenceable.
* Mutually exclusive with type().
* @return fully qualified class name
*/
String typeName() default "";
/**
* Name of the method to select.
* Used with type() or typeName().
* @return method name
*/
String name() default "";
/**
* Parameter types for method overload resolution.
* Mutually exclusive with parameterTypeNames().
* @return array of parameter types
*/
Class<?>[] parameterTypes() default {};
/**
* Parameter type names for method overload resolution.
* Alternative to parameterTypes() using string names.
* Mutually exclusive with parameterTypes().
* @return comma-separated parameter type names
*/
String parameterTypeNames() default "";
}
/**
* Container annotation for multiple @SelectMethod declarations.
* @since 1.10
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = EXPERIMENTAL, since = "1.10")
public @interface SelectMethods {
SelectMethod[] value();
}Usage Examples:
// Fully qualified method names
@Suite
@SelectMethod("com.example.UserTest#testCreateUser")
@SelectMethod("com.example.UserTest#testUpdateUser(com.example.User)")
class UserMethodSuite {
}
// Class and method name combinations
@Suite
@SelectMethod(type = UserTest.class, name = "testCreateUser")
@SelectMethod(type = ProductTest.class, name = "testValidateProduct")
class CrossClassMethodSuite {
}
// String-based class names with parameter types
@Suite
@SelectMethod(
typeName = "com.example.internal.ServiceTest",
name = "testComplexOperation",
parameterTypeNames = "java.lang.String, int, boolean"
)
class InternalMethodSuite {
}
// Overloaded method selection
@Suite
@SelectMethod(
type = CalculatorTest.class,
name = "testAdd",
parameterTypes = {int.class, int.class}
)
@SelectMethod(
type = CalculatorTest.class,
name = "testAdd",
parameterTypes = {double.class, double.class}
)
class OverloadedMethodSuite {
}Selects tests based on prefixed selector identifiers, providing a unified interface for various selection strategies.
/**
* Selects tests based on prefixed selector identifiers.
* Uses DiscoverySelectors.parse(String) for parsing selector syntax.
* Supports class:, method:, package:, file:, directory:, uri:, module: prefixes.
*
* @since 1.11
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@Repeatable(Selects.class)
@API(status = EXPERIMENTAL, since = "1.11")
public @interface Select {
/**
* One or more prefixed selector identifiers.
* @return array of selector identifiers to parse and apply
*/
String[] value();
}
/**
* Container annotation for multiple @Select declarations.
* @since 1.11
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = EXPERIMENTAL, since = "1.11")
public @interface Selects {
Select[] value();
}Usage Examples:
// Mixed selector types
@Suite
@Select({
"class:com.example.UserTest",
"method:com.example.ProductTest#testValidation",
"package:com.example.integration"
})
class MixedSelectorSuite {
}
// File and directory selectors
@Suite
@Select({
"file:src/test/java/UserTest.java",
"directory:src/test/java/integration"
})
class FileBasedSuite {
}Annotations for selecting tests based on file system paths and classpath resources.
/**
* Specifies a file to select for test suite execution.
* @since 1.8
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@Repeatable(SelectFiles.class)
@API(status = STABLE, since = "1.10")
public @interface SelectFile {
/**
* The file to select for test execution.
* @return file path to select
*/
String value();
/**
* Line number within the file (ignored if ≤ 0).
* @return line number for precise selection
*/
int line() default 0;
/**
* Column number within the file (ignored if line ignored or ≤ 0).
* @return column number for precise selection
*/
int column() default 0;
}
/**
* Container for multiple @SelectFile declarations.
* @since 1.8
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = STABLE, since = "1.10")
public @interface SelectFiles {
SelectFile[] value();
}
/**
* Specifies directories to select for test suite execution.
* @since 1.8
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = STABLE, since = "1.10")
public @interface SelectDirectories {
/**
* One or more directories to select for test discovery.
* @return array of directory paths
*/
String[] value();
}
/**
* Specifies a classpath resource to select for test suite execution.
* @since 1.8
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@Repeatable(SelectClasspathResources.class)
@API(status = STABLE, since = "1.10")
public @interface SelectClasspathResource {
/**
* Name of classpath resource to select.
* @return classpath resource name
*/
String value();
/**
* Line number within the resource (ignored if ≤ 0).
* @return line number for precise selection
*/
int line() default 0;
/**
* Column number within the resource (ignored if line ignored or ≤ 0).
* @return column number for precise selection
*/
int column() default 0;
}
/**
* Container for multiple @SelectClasspathResource declarations.
* @since 1.8
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = STABLE, since = "1.10")
public @interface SelectClasspathResources {
SelectClasspathResource[] value();
}Usage Examples:
// File selection with line numbers
@Suite
@SelectFile(value = "src/test/java/UserTest.java", line = 45)
@SelectFile("src/test/java/ProductTest.java")
class FileBasedSuite {
}
// Directory selection
@Suite
@SelectDirectories({
"src/test/java/unit",
"src/test/java/integration"
})
class DirectoryBasedSuite {
}
// Classpath resource selection
@Suite
@SelectClasspathResource("test-scenarios.json")
@SelectClasspathResource(value = "integration-tests.xml", line = 25)
class ResourceBasedSuite {
}Advanced selection capabilities for modular systems and URI-based test identification.
/**
* Specifies modules to select for test suite execution.
* @since 1.8
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = STABLE, since = "1.10")
public @interface SelectModules {
/**
* One or more modules to select for test discovery.
* @return array of module names
*/
String[] value();
}
/**
* Specifies URIs to select for test suite execution.
* @since 1.8
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = STABLE, since = "1.10")
public @interface SelectUris {
/**
* One or more URIs to select for test discovery.
* @return array of URI strings
*/
String[] value();
}Usage Examples:
// Module selection for modular applications
@Suite
@SelectModules({
"com.example.core",
"com.example.integration"
})
class ModularSuite {
}
// URI-based selection
@Suite
@SelectUris({
"classpath:com/example/tests/",
"file:///absolute/path/to/tests/"
})
class UriBasedSuite {
}Direct specification of test classes:
@Suite
@SelectClasses({
UserServiceTest.class,
UserRepositoryTest.class,
UserControllerTest.class
})
class UserModuleSuite {
}Package selection with filtering:
@Suite
@SelectPackages("com.example")
@IncludeClassNamePatterns(".*IntegrationTest")
@ExcludeClassNamePatterns(".*AbstractIntegrationTest")
class IntegrationSuite {
}Specific method selection:
@Suite
@SelectMethod(type = ServiceTest.class, name = "testCriticalFeature")
@SelectMethod("com.example.UtilTest#testSpecialCase(java.lang.String)")
class CriticalFeatureSuite {
}Combining multiple selection approaches:
@Suite
@SelectClasses({CoreTest.class}) // Explicit classes
@SelectPackages("com.example.integration") // Package discovery
@SelectMethod(type = UtilTest.class, name = "specialTest") // Specific methods
@SelectFiles("src/test/resources/scenarios.feature") // File-based tests
class ComprehensiveSelectionSuite {
}Install with Tessl CLI
npx tessl i tessl/maven-org-junit-platform--junit-platform-suite