Search⌘ K
AI Features

Tags and Filtering

Explore how to apply and manage JUnit 5 tags using the @Tag annotation. Understand type-safe tags, multiple tagging, and syntax rules. Learn to filter tests by tags in Gradle and Maven to control test execution efficiently.

Testing with @Tag

Tags are added using the annotation org.junit.jupiter.api.Tag. The @Tag annotation is repeatable, so we can put multiple annotations in the same class or method. We can also use org.junit.jupiter.api.Tags to specify multiple tags. Tags are first trimmed by using String.trim(). A tag can’t be null or empty. A trimmed tag can’t contain whitespace or ISO control characters. For example, @Tag("hello world") is invalid.

Note: We can still add trimmed tags with whitespaces to our test classes ...