我能否通过Maven运行特定的TestNG测试组?

29

我有几个TestNG测试组,例如group1、group2、group3... 这些都在我的pom.xml文件中定义,并且当我执行 "mvn test" 时会运行所有测试组。如果我只想运行一个测试组而不必修改pom.xml中的配置,我需要运行什么命令?

例如:mvn test group2、mvn test group1、mvn test group3

4个回答

53

尝试

mvn test -Dgroups=group3,group2

有没有办法运行同时包含“group3”和“group2”的测试? - hpaknia

7
我在查找如何禁用特定测试组时遇到了这个问题,而Radadiya的答案让我有点困惑。
要运行特定的测试组,请使用Eugene Kuleshov提到的以下方法。 文档
mvn test -Dgroups=group1,group2

但是如果要排除某些分组,请使用这个命令(请注意exclude中的d与include不同)。文档

mvn test -DexcludedGroups=group3,group4

2
您可以在Maven测试执行期间包含和排除特定的组。
(1)包含特定组
mvn clean test -DincludeGroups=TestGroup1,TestGroup2

(2) 排除特定的组

mvn clean test -DexcludeGroups=TestGroup3,TestGroup4

请查看Mikalai的帖子,其中包含到Maven文档的链接。 - ChuckB
includeGroups doesn't seem to exist. Use the suggested groups - Michael Laffargue

0

您还可以运行具有组合的测试。这将执行标记为“group1”和“group2”的测试:

mvn test -Dgroups=group1&group2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接