【发布时间】:2015-11-04 15:02:00
【问题描述】:
我想使用 Maven 通过命令行基于他们的组运行我的测试。(意味着如果我说mvn test -Dgroups=sanity,则只会运行标记为sanity 组的测试)
为了实现上述目标,我在 pom.xml 中编写了以下代码。因为如果没有在命令行上为组(即mvn test)提供任何内容,它将使用regression 组运行测试
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.maven.test</groupId>
<artifactId>MavenTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<groups>regression</groups>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<groups>${groups}</groups>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
我的测试类有BeforeClass 和AfterClass 注释:
public class SanityTest {
@Test(groups={"sanity"})
public void f() {
System.out.println("This is sanity test");
}
@BeforeClass
public void beforeClass() {
System.out.println("This is before class.");
}
@AfterClass
public void afterClass() {
System.out.println("This is after class.");
}
}
为了运行健全性测试,我点击了mvn test -Dgroups=sanity。健全性测试会运行,但不会执行 AfterClass、BeforeClass 方法。
它的输出是:
This is sanity test
实际上,我在这里期待:
This is before class.
This is sanity test
This is after class.
有人可以帮我做什么,以便同时尊重 TestNG 注释吗?
【问题讨论】:
-
显示完整的 pom 文件,请添加完整的输出
mvn clean test.. -
khmarbaise,我用完整的 pom.xml 更新了问题。我应该添加
mvn clean test或mvn clean test -Dgroups=sanity的输出吗?
标签: java maven selenium-webdriver testng maven-surefire-plugin