maven配置testng_TestNG Maven Surefire插件配置

  • Post author:
  • Post category:其他


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.xml



test_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 install



mvn 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套件文件的全部。

翻译自:

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

maven配置testng