There is a newer version available.
For the latest stable version, please use JUnit 6.0.1!

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 null or blank.

  • A stripped tag must not contain whitespace.

  • A stripped tag must not contain ISO control characters.

  • A stripped tag must not contain any of the following reserved characters.

    • ,: comma

    • (: left parenthesis

    • ): right parenthesis

    • &: ampersand

    • |: vertical bar

    • !: exclamation point

In the above context, "stripped" means that leading and trailing whitespace characters have been removed using java.lang.String.strip().

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.

Operators (in descending order of precedence)
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

product

all tests for product

catalog | shipping

all tests for catalog plus all tests for shipping

catalog & shipping

all tests for the intersection between catalog and shipping

product & !end-to-end

all tests for product, but not the end-to-end tests

(micro | integration) & (product | shipping)

all micro or integration tests for product or shipping