【发布时间】:2019-01-14 20:48:00
【问题描述】:
我想过滤我的 Junit 5 测试用例,我正在使用注解 @Tag("type_test")。我使用命令mvn -Dtests=a test 使用maven 运行我的测试,但它运行所有情况。例如,我有两个方法,我只想运行 @Tag("a") 的方法,但控制台中的结果是“Hello word 1”和“Hello word 2”。请参阅示例代码。
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>
【问题讨论】:
标签: java maven maven-surefire-plugin junit5