How to Tag Tests in JUnit 5

In this tutorial, we are going to learn how to Tag Tests using JUnit Jupiter tests.

Test classes and methods can be tagged in the JUnit 5 programming model by means of the annotation @Tag. Those tags can later be used to filter test discovery and execution. In this example, we see the use of @org.junit.jupiter.api.Tag at class level and also at method level.

package com.example;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Tag;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AppTest 


    void testOne() {

    void testTwo() {

    void testThree() {


Now how to choose which of the tagged Tests can be executed? There are two simple ways: one is specifying in the maven-surfire plugin which Test Tags we want to execute:


Another option is to use a simple TestSuite class which uses the @IncludeTags to specify the list of @Tag Tests:

package com.example;

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.IncludeTags;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.runner.RunWith;

public class TestSuiteDemo {

For example, if we were to run this TestSuite, we would fire all tests, as the “all” Tag has been placed at Class level:

junit jupiter tags tutorial tag