2.8. Tagging and Filtering

Test classes and methods can be tagged via the @Tag annotation. Those tags can later be used to filter test discovery and execution.

See also: Tag Expressions

2.8.1. Syntax Rules for Tags

  • A tag must not be null or 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.
  1. import org.junit.jupiter.api.Tag;
  2. import org.junit.jupiter.api.Test;
  3. @Tag("fast")
  4. @Tag("model")
  5. class TaggingDemo {
  6. @Test
  7. @Tag("taxes")
  8. void testingTaxCalculation() {
  9. }
  10. }
See Meta-Annotations and Composed Annotations for examples demonstrating how to create custom annotations for tags.