我使用TestNG和Maven with surefire插件来运行测试。 我:TestNG mvn运行测试无组
@Test(groups={"groupA"})
TestA{}
@Test
TestB
我想有可能运行:
mvn test
应该调用所有测试没有任何组
mvn test -Dgroups=groupA
应该只调用A组试验(这是通过默认,但只是在这里添加使它与以前的选项)
我想配置万无一失,如:如预期
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<excludedGroups>groupA</excludedGroups>
</configuration>
</plugin>
MVN测试作品,但经过
MVN测试-Dgroups = A组 没有测试执行
编辑
我在这里找到解决方案: https://labs.consol.de/blog/maven/citrus-and-testng-groups/
<!-- TestNG groups -->
<testGroups></testGroups>
<testGroupsExcluded>groupA</testGroupsExcluded>
<!-- /TestNG groups-->
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<groups>${testGroups}</groups>
<excludedGroups>${testGroupsExcluded}</excludedGroups>
</configuration>
...
<profile>
<id>a-testes</id>
<properties>
<testGroups>a</testGroups>
<testGroupsExcluded></testGroupsExcluded>
</properties>
</profile>
但是这个解决方案有一个问题。当我们想要只运行一组测试时,它工作正常,例如mvn测试-P a-tests,但是当我们将添加另一个组时,我们说b-测试,然后在之后mvn测试-P a-tests ,B测试只有一个组将被执行,因为最后定义的配置文件将覆盖属性...任何想法如何组合testGroupsExcluded,testGroups属性来自多个配置文件?
编辑2
我只是解决
<properties>
<testGroups>unit</testGroups>
</properties>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<groups>${testGroups}</groups>
</configuration>
</plugin>
结束,但我必须明确指定了所有的考试,以组(所有未分配的测试现在是“单位”),但现在我可拨打:
MVN测试要调用标记为单元的所有测试
个MVN测试-DtestGroups = A组,B组调用任何组测试...