【发布时间】:2010-11-11 22:34:57
【问题描述】:
我想使用 Maven 和 TestNG 从命令行运行单个测试类
不起作用的事情:
mvn -Dtest=ClassName test
我在 pom.xml 中定义了组,而这个类不在其中一个组中。所以它基于这些理由被排除在外。
mvn -Dgroups=skipped-group test
mvn -Dsurefire.groups=skipped-group test
配置时
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<groups>functest</groups>
</configuration>
</plugin>
在 pom.xml 中没有定义组时,参数工作正常。
同样,当surefire配置为
<configuration>
<includes>
<include>**/*UnitTest.java</include>
</includes>
</configuration>
我可以使用-Dtest 参数添加另一个测试,但不能添加组。在任何组合中,我都可以缩小要与组一起执行的测试,但不能扩展它们。
我的配置有什么问题?有没有办法在 pom.xml 中定义的测试或组之外运行单个测试或组?
在 Ubuntu 10.04 上尝试使用 Maven 2.2.1、TestNG 5.14.6 和 Surefire 2.7.1
【问题讨论】:
-
以前从未遇到过这个问题。检查您使用的surefire 版本是最新的。除此之外,我通常会运行我的单个测试,例如: mvn test -Dtest=ClassName (交换参数)。但我不认为这应该有所作为
标签: java unit-testing maven-2 testng surefire