gpt4 book ai didi

maven - surefire-plugin 不尊重 threadCount 参数

转载 作者:行者123 更新时间:2023-12-03 17:06:34 25 4
gpt4 key购买 nike

几天以来,我试图查看在并行运行 Selenium 测试的配置中我的错误在哪里。

我有一个带有 2 个节点的 Selenium Grid。
在我的 pom.xml 中,我设置了 Surefire 以 2 x 2 运行我的测试方法,然后是其他测试。

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<executions>
<execution>
<id>default-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<parallel>methods</parallel>
<perCoreThreadCount>false</perCoreThreadCount>

<threadCount>2</threadCount>
<reuseForks>false</reuseForks>
<groups>
com.something.categories.Safe,
com.something.categories.Parallel
</groups>
</configuration>
</execution>
<execution>
<id>no-safe</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludedGroups>
com.something.categories.Safe,
com.something.Parallel
</excludedGroups>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

当我启动我的测试 mvn clean test -Dtest='TestAwesome' 包含在 TestAwesome 中的所有测试同时启动(我看到超过 2 个浏览器打开),因此不尊重我的 threadCount 值。

我错过了什么?

回答后版
这是我的部分 pom.xml 来解决我的问题
<profiles>
<profile>
<id>selenium-tests</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>all</parallel>
<threadCount>${threads}</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
<useUnlimitedThreads>true</useUnlimitedThreads>
<systemProperties>
<browser>${browser}</browser>
<screenshotDirectory>${project.build.directory}/screenshots</screenshotDirectory>
<gridURL>${seleniumGridURL}</gridURL>
<env>${env}</env>
</systemProperties>
<groups>${groups}</groups>
<excludedGroups>${excludedGroups}</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

最佳答案

由于您使用的是足够现代的 surefire 版本,您可能想尝试将 threadCountMethods 参数而不是 threadCount 与 useUnlimitedThreads = true 结合使用,即使这看起来违反直觉。

surefire jUnit examples :

As of Surefire 2.7, no additional dependencies are needed to use the full set of options with parallel. As of Surefire 2.16, new thread-count attributes are introduced, namely threadCountSuites, threadCountClasses and threadCountMethods.



Fork options and parallel execution :

As an example with an unlimited number of threads, there is maximum of three concurrent threads to execute suites: parallel = all, useUnlimitedThreads = true, threadCountSuites = 3.

关于maven - surefire-plugin 不尊重 threadCount 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31478195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com