I want to filter my Junit 5 test cases, I am using the annotation @Tag("type_test"). I run my test with maven with the command mvn -Dtests=a test but it runs all the cases. For example, I have two methods and I want run only the method with @Tag("a"), but the result in console is "Hello word 1" and "Hello word 2". See the example code.
static Properties properties = null;
@BeforeAll
public static void setUp() throws Throwable {
properties = CommonMethods.loadConfigPropertiesFile();
RestAssured.baseURI = properties.getProperty("BASE_HOST");
}
@Test
@Tag("a")
public void test1() {
System.out.println("hello word 1");
}
@Test
@Tag("b")
public void test2() {
System.out.println("hello word 2");
}
}
pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<properties>
<includeTags>${tests}</includeTags>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.0-M2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.0-M2</version>
</dependency>
</dependencies>