但是,我怀疑我是这个星球上第一个尝试与Jenkins并行运行单元测试的人,并希望使用TestNG Jenkins插件正确显示结果,所以我很确定必须有一个解决方案,对吧?
However, I doubt that I'm the first person on the planet who is trying to run unit tests in parallel with Jenkins and wants the results displayed properly using the TestNG Jenkins plugin, so I'm pretty sure there must be a solution for this, right?
这是我的surefire插件配置:
Here's my surefire plugin config:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${basepom.plugin.surefire.version}</version>
<configuration>
<forkCount>2.5C</forkCount>
<reuseForks>false</reuseForks>
</configuration>
</plugin>
这是surefire配置的链接.
Here's the link to the surefire config btw.:
推荐答案
我实际上最终找到了对我有用的解决方案.
I actually ended up finding a solution that worked for me.
我认为问题在于尝试使用forkCount/reuseForks进行操作,因此我将其设置为默认值(如果您不打算覆盖基本pom等内容,也可以跳过这些属性. ).
I think the problem is trying to do it with forkCount / reuseForks, so I've set those back to the default (you could also just skip those properties if you're not trying to overwrite something from a base pom etc.).
相反,我使用了parallel和threadCount.但是,这些仅适用于TestNG,但是对于TestNG(不是JUnit),我也需要它.
Instead I've used parallel and threadCount. Those however only apply to TestNG, but then, I also need it for TestNG (not JUnit).
这使得测试可以并行运行,但是testng-results.xml可以正确生成(不会被并行运行的每个测试覆盖).
This makes tests run in parallel, but the testng-results.xml is generated correctly (without being overwritten by each test running in parallel).
此处有更多详细信息:
这是我现在拥有的插件配置:
Here's the plugin configuration I have now:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- those are the two default values, you can probably skip them -->
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<!-- that's what made it work -->
<parallel>classes</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
很明显,线程数可以根据您要执行的操作/服务器的规格而定,可以更低或更高,并且可以根据是否要运行类或并行运行其他级别"来更改设置.
Obviously, the thread count could be lower or higher depending on what you want to do / what specs your server has, and you could change the settings depending on whether you want to run classes, or some other "level" in parallel.
此外,如果您选择使用套件文件,则可以在套件文件中配置parallel和threadCount以及任何其他属性.
Also, you could configure parallel and threadCount together with any other properties in the suite file, if you choose to use a suite file.
这篇关于与surefire并行运行测试,并使用TestNG Jenkins插件正确显示它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!