Annotation Interface Testable
@Testable is 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
as 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
@Testable therefore serves as an alternative mechanism for
IDEs to discover potential tests by analyzing the source code only.
Common Use Cases
@Testable will typically be used as a meta-annotation in order to
create a custom composed annotation that inherits the semantics
@Testable. For example, the
annotations 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
Alternatively, if concrete test classes extend from a base class, the base class
can be annotated with
@Testable. Note that
@Testable is an
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
TestEngine must not in any way perform
discovery based on the presence of
@Testable. In terms of
discovery, the presence of
@Testable should only be meaningful to
clients such as IDEs and tooling vendors. A
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,
@Testable may target any
declaration element type. This
includes the aforementioned method, field, and class elements.