Test classes and methods can be tagged in the JUnit 5 programming model by means of the annotation @Tag (package org.junit.jupiter.api). Those tags can later be used to filter test discovery and execution. In the following example, we see the use of @Tag at class level and also at method level:
package io.github.bonigarcia;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@Tag("simple")
class SimpleTaggingTest {
@Test
@Tag("taxes")
void testingTaxCalculation() {
}
}
As of JUnit 5 M6, the label for tagging tests should meet the following syntax rules:
- A tag must not be null or blank.
- A trimmed tag (that is, tags in which leading and trailing whitespace have been removed) must not contain a white space.
- A trimmed tag must not contain ISO control characters nor the following reserved characters...