TestNG测试重叠组不能与maven中的excludeGroups一起使用

时间:2012-10-05 13:41:56

标签: maven testng

我试图将测试分成组,例如,“FULL”执行组和更轻的“SMOKE”组。我想在主pom中有一个默认配置文件,它只运行SMOKE组,然后让CI服务器激活一个单独的FULL组,它执行所有测试。

但是,我在让maven / testng仅执行SMOKE集时遇到问题。当我将FULL组添加到excludedGroups时,不会执行任何测试。

我对maven-surefire-plugin的有效pom是这样的:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.6</version>
    <executions>
      <execution>
        <id>default-test</id>
        <phase>test</phase>
        <goals>
          <goal>test</goal>
        </goals>
        <configuration>
          <groups>USER</groups>
          <excludedGroups>FULL</excludedGroups>
        </configuration>
      </execution>
    </executions>
    <configuration>
      <groups>USER</groups>
      <excludedGroups>FULL</excludedGroups>
    </configuration>
  </plugin>

我的测试类因此被注释:

@Test(groups = { "FULL", "SMOKE" }, enabled=true)
public void testOne() { }

@Test(groups = { "FULL" }, enabled=true)
public void testTwo() { }

每个班级为SMOKE考试组选择一个代表性考试。我试图省略excludedGroups标记,只将groups标记设置为SMOKE,然后执行所有测试。

任何帮助我理解testng组层次结构的帮助都将受到赞赏。

1 个答案:

答案 0 :(得分:1)

首先,当您在excludedGroups中给出FULL时,预期行为不会运行任何测试,因为它排除了所有具有它的测试用例。如果您只想运行SMOKE,则只能按以下方式分组SMOKE。

<plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.6</version>
          <executions>
              <execution>
                  <id>default-test</id>
                  <phase>test</phase>
                  <goals>
                      <goal>test</goal>
                  </goals>
              </execution>
          </executions>
          <configuration>
              <groups>SMOKE</groups>
          </configuration>
      </plugin>

上面的配置对我来说很好。

下面的config只运行testTwo()。

<configuration>
              <groups>FULL</groups>
              <excludedGroups>SMOKE</excludedGroups>
          </configuration>

测试用例即使被明确排除也会被执行的唯一情况(我能想到)将是当一些其他测试用例依赖于(testng'依赖')此测试并且包含执行的依赖测试用例时