Tags
Tags are a JUnit Platform concept for marking and filtering tests. The programming model
for adding tags to containers and tests is defined by the testing framework. For example,
in JUnit Jupiter based tests, the @Tag annotation (see
Tagging and Filtering) should be used. For JUnit 4 based tests, the
Vintage engine maps @Category annotations to tags (see
Categories Support). Other testing frameworks may define their
own annotation or other means for users to specify tags.
Syntax Rules for Tags
Regardless how a tag is specified, the JUnit Platform enforces the following rules:
-
A tag must not be
nullor blank. -
A trimmed tag must not contain whitespace.
-
A trimmed tag must not contain ISO control characters.
-
A trimmed tag must not contain any of the following reserved characters.
-
,: comma -
(: left parenthesis -
): right parenthesis -
&: ampersand -
|: vertical bar -
!: exclamation point
-
| In the above context, "trimmed" means that leading and trailing whitespace characters have been removed. |
Tag Expressions
Tag expressions are boolean expressions with the operators !, & and |. In addition,
( and ) can be used to adjust for operator precedence.
Two special expressions are supported, any() and none(), which select all tests with
any tags at all, and all tests without any tags, respectively.
These special expressions may be combined with other expressions just like normal tags.
| Operator | Meaning | Associativity |
|---|---|---|
|
not |
right |
|
and |
left |
|
or |
left |
If you are tagging your tests across multiple dimensions, tag expressions help you to select which tests to execute. When tagging by test type (e.g., micro, integration, end-to-end) and feature (e.g., product, catalog, shipping), the following tag expressions can be useful.
| Tag Expression | Selection |
|---|---|
|
all tests for product |
|
all tests for catalog plus all tests for shipping |
|
all tests for the intersection between catalog and shipping |
|
all tests for product, but not the end-to-end tests |
|
all micro or integration tests for product or shipping |