使用testng和maven运行不同的测试套件

eka*_*aqu 3 testng maven maven-surefire-plugin

我正在使用TestNg和Maven以及surefire插件来运行我的测试.我有几个不同的组件,我希望能够使用相同的pom在不同的时间运行.目前为了做到这一点,我有几个不同的XML文件定义测试套件,我有pom设置,所以我可以做mvn test -Dtestfile =/path并使用该套件.

我想知道是否有办法将XML文件合并到一个文件中并选择基于测试名或其他系统?

编辑:我已经使用Smoke,Sanity,Regression定义了所有测试,并且我希望能够为给定组件运行所有回归.如果我运行TestNG CLI,我可以给出-testnames comp1,comp2,comp3等.其中每个组件在一个包含多个tests()的xml套件中定义.我想知道是否有任何方法可以在maven中使用exec:java插件.

mdm*_*dma 7

TestNG支持测试组,可以通过在测试用例本身中的测试类/方法上指定组,也可以在suite.xml文件中指定组.通过使用组,您可以将所有测试放在一个xml文件中.见 TestNG的用户指南中.

surefire插件允许根据组包含或排除测试:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.8.1</version>
        <configuration>
          <groups>${testng.groups}</groups>
        </configuration>
      </plugin>
Run Code Online (Sandbox Code Playgroud)

您可以将所有测试放在一个xml文件中,然后通过将一个或多个组设置为包含在$ {testng.groups}属性中来选择要运行的测试,该属性应该是以逗号分隔的组名列表.

您可以使用配置文件或命令行在POM中定义$ {testng.groups}属性的值-Dtestng.groups=[groups to run].


khm*_*ise 6

您可以做的是定义不同的配置文件

  <profiles>
    <profile>
      <id>t1</id>
      <build>
        <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.8.1</version>
          <configuration>
            <suiteXmlFiles>
              <suiteXmlFile>testng.xml</suiteXmlFile>
            </suiteXmlFiles>
          </configuration>
        </plugin>
      </plugins>
      </build>
     </profile>
   </profiles>
Run Code Online (Sandbox Code Playgroud)

并通过mvn -Pt1从命令行调用...或在配置文件中定义属性并在配置中使用该属性.