简体   繁体   English

与surefire maven插件并行运行junit测试

[英]Run junit test in parallel with surefire maven plugin

It is posible to configure surefire plugin to only run some test in parallel and others in sequence?是否可以将 surefire 插件配置为仅并行运行一些测试而其他测试则按顺序运行?

Also can surefire forkCount be used to run parallel tests declared into a jUnit Suite?还可以使用surefire forkCount来运行声明到jUnit 套件中的并行测试吗?

您可以将单独的 Maven 配置文件与两个不同的 surefire 插件配置一起使用。

A very easy way to do this is as follows:一个非常简单的方法如下:

  • Move sequential tests each into its own test suite in junit在 junit 中将每个顺序测试移动到自己的测试套件中
  • Move parallel tests all into the same suite.将所有并行测试移到同一个套件中。
  • Set Parallel to "classes"将 Parallel 设置为“类”

 configuration> <includes> <include>**/A01TestSuite.java</include> <include>**/A02ServiceTestSuite.java</include> <include>**/A03FlowTestSuite.java</include> </includes> <additionalClasspathElements> <additionalClasspathElement>${webinf.dir}</additionalClasspathElement> </additionalClasspathElements> <systemPropertyVariables> <log4j.configuration>file:${l4j.test}/log4j.test.properties</log4j.configuration> </systemPropertyVariables> <forkMode>always</forkMode> <argLine>-Xms512m -Xmx512m</argLine> <parallel>classes</parallel> <threadCount>10</threadCount> </configuration>

You can add this to the configuration of the maven-surefire-plugin in the pom.xml file.您可以将其添加到 pom.xml 文件中 maven-surefire-plugin 的配置中。

<configuration>
    <parallel>all</parallel>
    <threadCount>10</threadCount>
    <threadCountSuites>2</threadCountSuites>
    <threadCountClasses>2</threadCountClasses>
    <threadCountMethods>6</threadCountMethods>
    <parallelTestTimeoutInSeconds>3.5</parallelTestTimeoutInSeconds>
    <parallelTestTimeoutForcedInSeconds>5</parallelTestTimeoutForcedInSeconds>
    <perCoreThreadCount>true</perCoreThreadCount>
    <includes>
        <include>**/FunctionTestSuite.java</include>
    </includes>
</configuration>

A detailed explanation can be found at this link .可以在此链接中找到详细说明。 It gives a complete description step by step to run JUnit tests parallel with surefire-maven-plugin.它逐步给出了与surefire-maven-plugin并行运行JUnit测试的完整描述。

Note: This code snippet shows all the available options.注意:此代码片段显示了所有可用选项。 You can change or remove some options as per your need!您可以根据需要更改或删除一些选项!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM