CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-junit-platform--junit-platform-suite-api

JUnit Platform Suite API provides annotations and configuration options for creating test suites with the JUnit Platform, including test selection, filtering, and configuration capabilities for organizing and executing collections of tests

Pending
Overview
Eval results
Files

selection.mddocs/

Test Selection

Comprehensive test selection capabilities supporting classes, packages, methods, files, resources, directories, modules, and URIs with flexible selector syntax.

Capabilities

@Select Annotation (Experimental)

General-purpose selector using prefixed selector identifiers for flexible test selection.

/**
 * Specifies which tests to select based on prefixed selector identifiers.
 * Repeatable annotation supporting various selector formats.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = EXPERIMENTAL, since = "1.11")
@Repeatable(Selects.class)
public @interface Select {
    /**
     * One or more prefixed selector identifiers to select.
     * @return array of selector identifiers
     */
    String[] value();
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = EXPERIMENTAL, since = "1.11")
public @interface Selects {
    Select[] value();
}

Usage Examples:

@Suite
@Select("class:com.example.UserTest")
@Select("method:com.example.UserTest#testValidUser")
@Select("package:com.example.integration")
public class FlexibleTestSuite {
}

// Multiple selectors in one annotation
@Suite
@Select({
    "class:com.example.UserTest",
    "class:com.example.ProductTest",
    "method:com.example.OrderTest#testCreateOrder"
})
public class MultiSelectSuite {
}

@SelectClasses Annotation

Specifies the classes to select when running a test suite.

/**
 * Specifies the classes to select when running a test suite.
 * Can use Class objects or fully qualified class names.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = MAINTAINED, since = "1.0")
public @interface SelectClasses {
    /**
     * One or more classes to select.
     * @return array of Class objects to select
     */
    Class<?>[] value() default {};
    
    /**
     * One or more classes by fully qualified names.
     * @return array of fully qualified class names
     * @since 1.10
     */
    @API(status = EXPERIMENTAL, since = "1.10")
    String[] names() default {};
}

Usage Examples:

// Using Class objects
@Suite
@SelectClasses({UserTest.class, ProductTest.class, OrderTest.class})
public class CoreTestSuite {
}

// Using class names (useful for conditional compilation)
@Suite
@SelectClasses(names = {
    "com.example.UserTest",
    "com.example.ProductTest",
    "com.example.integration.DatabaseTest"
})
public class NameBasedTestSuite {
}

// Combining both approaches
@Suite
@SelectClasses(
    value = {UserTest.class, ProductTest.class},
    names = {"com.example.integration.ExternalApiTest"}
)
public class HybridTestSuite {
}

@SelectPackages Annotation

Specifies package names to select for test suite execution.

/**
 * Specifies the names of packages to select when running a test suite.
 * All test classes in specified packages will be selected.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = MAINTAINED, since = "1.0")
public @interface SelectPackages {
    /**
     * One or more fully qualified package names to select.
     * @return array of package names
     */
    String[] value();
}

Usage Examples:

// Single package
@Suite
@SelectPackages("com.example.unit")
public class UnitTestSuite {
}

// Multiple packages
@Suite
@SelectPackages({
    "com.example.unit",
    "com.example.integration", 
    "com.example.performance"
})
public class ComprehensiveTestSuite {
}

@SelectModules Annotation

Specifies modules to select for test suite execution (Java 9+ module system).

/**
 * Specifies the modules to select when running a test suite.
 * Useful for modular Java applications.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = STABLE, since = "1.10")
public @interface SelectModules {
    /**
     * One or more modules to select.
     * @return array of module names
     */
    String[] value();
}

Usage Examples:

@Suite
@SelectModules({"com.example.core", "com.example.api"})
public class ModularTestSuite {
}

Method Selection Annotations

Precise method-level test selection with flexible parameter specification.

/**
 * Specifies a method to select when running a test suite.
 * Supports various method specification formats.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE) 
@Inherited
@Documented
@API(status = EXPERIMENTAL, since = "1.10")
@Repeatable(SelectMethods.class)
public @interface SelectMethod {
    /**
     * Fully qualified method name (cannot be combined with other attributes).
     * Format: "com.example.MyClass#methodName"
     * @return fully qualified method name
     */
    String value() default "";
    
    /**
     * Class in which method is declared (cannot use with typeName()).
     * @return class containing the method
     */
    Class<?> type() default Class.class;
    
    /**
     * Fully qualified class name (cannot use with type()).
     * @return fully qualified class name
     */
    String typeName() default "";
    
    /**
     * Method name (never blank unless value() is used).
     * @return method name
     */
    String name() default "";
    
    /**
     * Parameter types (cannot use with parameterTypeNames()).
     * @return array of parameter types
     */
    Class<?>[] parameterTypes() default {};
    
    /**
     * Parameter types as string (cannot use with parameterTypes()).
     * Format: "java.lang.String, int, boolean"
     * @return comma-separated parameter type names
     */
    String parameterTypeNames() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = EXPERIMENTAL, since = "1.10")
public @interface SelectMethods {
    SelectMethod[] value();
}

Usage Examples:

// Using fully qualified method name
@Suite
@SelectMethod("com.example.UserTest#testValidUser")
@SelectMethod("com.example.UserTest#testInvalidUser")
public class UserTestMethodSuite {
}

// Using type and method name
@Suite
@SelectMethod(type = UserTest.class, name = "testValidUser")
@SelectMethod(type = ProductTest.class, name = "testProductCreation")
public class SpecificMethodSuite {
}

// With parameter types
@Suite
@SelectMethod(
    type = UserTest.class,
    name = "testUserWithAge", 
    parameterTypes = {String.class, int.class}
)
public class ParameterizedMethodSuite {
}

// Using type name and parameter type names
@Suite
@SelectMethod(
    typeName = "com.example.UserTest",
    name = "testComplexMethod",
    parameterTypeNames = "java.lang.String, int, boolean"
)
public class ComplexMethodSuite {
}

File and Resource Selection

Select tests from specific files, directories, classpath resources, and URIs.

/**
 * Specifies a file to select when running a test suite.
 * Supports line and column specification for precise selection.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = STABLE, since = "1.10")
@Repeatable(SelectFiles.class)
public @interface SelectFile {
    /**
     * The file to select.
     * @return file path
     */
    String value();
    
    /**
     * Line number within the file (ignored if ≤ 0).
     * @return line number
     */
    int line() default 0;
    
    /**
     * Column number within the file (ignored if line ignored or ≤ 0).
     * @return column number
     */
    int column() default 0;
}

/**
 * Specifies directories to select when running a test suite.
 */
@API(status = STABLE, since = "1.10")
public @interface SelectDirectories {
    String[] value();
}

/**
 * Specifies URIs to select when running a test suite.
 */
@API(status = STABLE, since = "1.10")
public @interface SelectUris {
    String[] value();
}

/**
 * Specifies a classpath resource to select when running a test suite.
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@Documented
@API(status = STABLE, since = "1.10")
@Repeatable(SelectClasspathResources.class)
public @interface SelectClasspathResource {
    /**
     * The name of the classpath resource to select.
     * @return classpath resource name
     */
    String value();
    
    /**
     * Line number within the resource (ignored if ≤ 0).
     * @return line number
     */
    int line() default 0;
    
    /**
     * Column number within the resource (ignored if line ignored or ≤ 0).
     * @return column number
     */
    int column() default 0;
}

Usage Examples:

// File selection
@Suite
@SelectFile("/path/to/TestFile.java")
@SelectFile(value = "/path/to/SpecificTest.java", line = 25)
public class FileBasedTestSuite {
}

// Directory selection
@Suite
@SelectDirectories({"/src/test/java/unit", "/src/test/java/integration"})
public class DirectoryTestSuite {
}

// Classpath resource selection
@Suite
@SelectClasspathResource("test-config/integration-tests.properties") 
@SelectClasspathResource(value = "test-data/user-scenarios.json", line = 10)
public class ResourceBasedTestSuite {
}

// URI selection
@Suite
@SelectUris({
    "file:///absolute/path/to/test",
    "classpath:/com/example/tests",
    "jar:file:/path/to/tests.jar!/com/example"
})
public class UriTestSuite {
}

Selection Best Practices

Combining Selectors

Multiple selection annotations can be combined to create complex test suites:

@Suite
@SelectPackages("com.example.core")
@SelectClasses({SpecialIntegrationTest.class})
@SelectMethod(type = PerformanceTest.class, name = "criticalPerformanceTest")
public class ComprehensiveTestSuite {
}

Performance Considerations

  • Use @SelectClasses for precise control and fastest execution
  • Use @SelectPackages for broad coverage with moderate performance
  • Use @SelectMethod sparingly for very specific test selection
  • Combine with filtering annotations to refine selection efficiently

Maintenance Tips

  • Use names attribute in @SelectClasses for conditional compilation scenarios
  • Group related test selections into logical suites
  • Consider using @Select for maximum flexibility in complex scenarios
  • Document selection criteria in suite class javadoc for maintenance clarity

Install with Tessl CLI

npx tessl i tessl/maven-org-junit-platform--junit-platform-suite-api

docs

configuration.md

core-framework.md

filtering.md

index.md

lifecycle.md

selection.md

tile.json