O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Tagging and filtering tests

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required