Annotation Type Testable
@Retention(RUNTIME) @Inherited @Documented @API(status=STABLE, since="1.0") public @interface Testable
@Testableis used to signal to IDEs and tooling vendors that the annotated or meta-annotated element is testable.
In this context, the term "testable" means that the annotated element (typically a method, field, or class) can be executed by a
TestEngineas a test or test container on the JUnit Platform.
Some clients of the JUnit Platform, notably IDEs such as IntelliJ IDEA, operate only on sources for test discovery. Thus, they cannot use the full runtime discovery mechanism of the JUnit Platform since it relies on compiled classes.
@Testabletherefore serves as an alternative mechanism for IDEs to discover potential tests by analyzing the source code only.
Common Use Cases
@Testablewill typically be used as a meta-annotation in order to create a custom composed annotation that inherits the semantics of
@Testable. For example, the
@TestFactoryannotations in JUnit Jupiter are meta-annotated with
For test programming models that do not rely on annotations, test classes, test methods, or test fields may be directly annotated with
@Testable. Alternatively, if concrete test classes extend from a base class, the base class can be annotated with
@Testable. Note that
Requirements for IDEs and Tooling Vendors
- If a top-level class, static nested class, or inner class is not
annotated or meta-annotated with
@Testablebut contains a method or field that is annotated or meta-annotated with
@Testable, the class must be considered to be a testable class.
- If annotation hierarchies containing
@Testableare present on classes, methods, or fields in compiled byte code (e.g., in JARs in the user's classpath), IDEs and tooling vendors must also take such annotation hierarchies into consideration when performing annotation processing for source code.
Restrictions for TestEngine Implementations
TestEnginemust not in any way perform discovery based on the presence of
@Testable. In terms of discovery, the presence of
@Testableshould only be meaningful to clients such as IDEs and tooling vendors. A
TestEngineimplementation is therefore required to discover tests based on information specific to that test engine (e.g., annotations specific to that test engine).
Supported Target Elements
Since JUnit Platform version 1.7,
@Testablemay target any declaration element type. This includes the aforementioned method, field, and class elements.
- If a top-level class, static nested class, or inner class is not annotated or meta-annotated with