【发布时间】:2018-07-21 13:03:32
【问题描述】:
我有一个设置Maven+JUnit5+Selenium,我的pom.xmlhttps://github.com/13Dima13/G/blob/master/pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<forkCount>4</forkCount>
<reuseForks>false</reuseForks>
<properties>
<includeTags>${tag}</includeTags>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-logger-api</artifactId>
<version>${surefire-logger-api}</version>
</dependency>
</dependencies>
</plugin>
首先我认为@Tag 工作正常,因为当我给我的班级添加注释时https://github.com/13Dima13/G/blob/master/src/test/java/com/example/project/TestThreads2.java
@Test
@Tag("smoke")
public void test1() {
open("https://mvnrepository.com/artifact/log4j/log4j/1.2.17");
$("#maincontent > table > tbody > tr:nth-child(1) > th").waitUntil(Condition.appears, 120000);
$("#maincontent > table > tbody > tr:nth-child(1) > th").shouldBe(Condition.text("License"));
assertEquals("Maven Repository: log4j » log4j » 1.2.17", title());
out.println("test1 Passed");
}
然后从终端运行
mvn test -Dtag=smoke
它只执行标记为@Tag("smoke") 的测试,所以在我的例子中只有一个测试,这让我很高兴。
但是 当我开始在我的实际项目中使用它时,我意识到它有时不起作用。
例如,如果我的带有测试方法的Test.class 没有放在父项目文件夹中(例如在项目文件夹的子文件夹中)https://github.com/13Dima13/G/blob/master/src/test/java/com/example/project/test2/GoogleSearch.java,则注释根本不起作用。
所以注释@Tag 不适用于整个项目还是我错过了什么?
【问题讨论】:
标签: maven selenium annotations tags junit5