Tags and Filtering
Learn how to add tags to test classes and methods and how to use filters in JUnit 5.
We'll cover the following...
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 ...