使用 testng 和 maven 运行不同的测试套件 [英] Running different test suites using testng and maven

查看:105
本文介绍了使用 testng 和 maven 运行不同的测试套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using TestNg and Maven with the surefire plugin to run my tests. I have several different components that I want to be able to run at different times using the same pom. Currently to do this I have several different XML files defining a test suite and I have the pom set up so i can do mvn test -Dtestfile=/path and use that suite instead.

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

I was wondering if there is a way to combine the XML files into one file and chose base off testnames or some other system?

我已经用 Smoke、Sanity、Regression 定义了我的所有测试,我希望能够运行给定组件的所有回归.如果我通过 TestNG CLI 运行,我可以给出 -testnames comp1、comp2、comp3 等.其中每个组件都定义在一个 xml 套件中,该套件包含多个测试 ().我想知道除了使用 exec:java 插件之外,在 Maven 中是否有任何方法可以做到这一点.

I have all my tests defined with Smoke, Sanity, Regression already and I would like to be able to run all Regressions for a given component. If I run through the TestNG CLI, I am able to give -testnames comp1,comp2,comp3,etc. where each component is defined in one xml suite which contains multiple tests (). I was wondering if there was any way to do this in maven short of using the exec:java plugin.

推荐答案

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

TestNG supports groups of tests, either by specifying groups on test classes/methods in the test cases themselves, or in the suite.xml file. By using groups, you can put all your tests in one xml file. See Groups in the TestNG user guide.

surefire 插件允许基于组包含或排除测试:

The surefire plugin allows tests to be included or excluded based on group:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.8.1</version>
        <configuration>
          <groups>${testng.groups}</groups>
        </configuration>
      </plugin>

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

You can put all your tests in one xml file, and then choose which ones to run by setting the group or groups to include in the ${testng.groups} property, which should be a comma-delimited list of group names.

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

You can define value for the ${testng.groups} property in the POM using profiles, or on the command-line -Dtestng.groups=[groups to run].

这篇关于使用 testng 和 maven 运行不同的测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆