maven配置testng_TestNG Maven Surefire插件配置

maven配置testng

TestNG Maven surefire plugin configurations let us define which tests to execute when we run the maven build. When we have a large project with many test cases, then it comes handy to configure only specific test suites for execution.

TestNG Maven surefire插件配置使我们可以定义运行maven构建时要执行的测试。 当我们有一个包含许多测试用例的大型项目时,仅配置用于执行的特定测试套件就很方便。

TestNG Maven项目 (TestNG Maven Project)

During the series of TestNG Tutorials here, I have created a lot of test classes and TestNG XML suite files. Below image shows the current project structure and all the test classes it has.

在这里的TestNG教程系列中,我创建了许多测试类和TestNG XML套件文件。 下图显示了当前的项目结构及其所有测试类。

Now when I run a maven build, it scans the project and executes all the test classes. So project build takes a lot of time. If I am interested in specific tests only, chances are that its logging gets lost in all the noise created by other tests.

现在,当我运行Maven构建时,它将扫描项目并执行所有测试类。 因此,项目构建需要很多时间。 如果我仅对特定测试感兴趣,则很可能它的日志记录会丢失于其他测试所产生的所有噪声中。

Maven Surefire插件 (Maven Surefire Plugin)

Maven surefire plugin is used to run the project tests. It also allows us to configure which XML suites to execute when we build our project. Below configuration will tell maven surefire plugin to execute only testng.xml and test_parameters.xml test suite files.

Maven surefire插件用于运行项目测试。 它还允许我们配置在构建项目时要执行的XML套件。 下面的配置将告诉Maven testng.xml插件仅执行testng.xmltest_parameters.xml测试套件文件。

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>2.21.0</version>
			<configuration>
                   <!-- TestNG Suite XML files list for test execution -->
                   <suiteXmlFiles>
                       <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                       <suiteXmlFile>src/test/resources/test_parameters.xml</suiteXmlFile>
                   </suiteXmlFiles>
               </configuration>
		</plugin>
	</plugins>
</build>

Now when we perform maven build by running mvn clean install or mvn test commands, we get a clean output for our tests.

现在,当我们通过运行mvn clean installmvn test命令执行maven构建时,我们将获得mvn test的干净输出。

That’s all for configuring maven-surefire-plugin to execute only specific TestNG XML suite files.

这就是配置maven-surefire-plugin仅执行特定的TestNG XML套件文件的全部。

GitHub Repository. GitHub Repository下载示例代码。

翻译自: https://www.journaldev.com/21326/testng-maven-surefire-plugin-configurations

maven配置testng

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值