surefire-plugin不遵守threadCount参数 [英] surefire-plugin does not respect threadCount parameter

查看:99
本文介绍了surefire-plugin不遵守threadCount参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天以来,我试图查看我的配置中并行运行Selenium测试的错误之处.

Since several days, I tried to see where is my mistake in my configuration to run in parallel my Selenium tests.

我有一个带有2个节点的Selenium Grid. 在我的pom.xml中,我将surefire设置为按2依次运行具有特定类别的测试方法和其他测试.

I have a Selenium Grid with 2 nodes. In my pom.xml, I have set surefire to run 2 by 2 the methods of my tests with a particular category then other tests.

<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中的所有测试是同时启动的(我看到打开了两个以上的浏览器),所以没有尊重我的threadCount值.

When I launch my test mvn clean test -Dtest='TestAwesome' all the tests contains in TestAwesome are launched in the same time (I see more than 2 browsers opended), and so does not respect my threadCount value.

我想念什么吗?

答案后的版本 这是我的部分pom.xml,用于解决我的问题

Edition after answer Here my partial pom.xml to solve my issue

<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,即使看起来违反直觉.

Since you are using a modern-enough version of surefire, you might wanna try the threadCountMethods parameter instead of threadCount in combination with useUnlimitedThreads = true, even though it seems counter-intuitive.

surefire jUnit示例:

从Surefire 2.7开始,不需要其他依赖项即可使用带有并行选项的完整选项集.从Surefire 2.16开始,引入了新的线程计数属性,即threadCountSuites,threadCountClasses和 threadCountMethods .

Fork选项和并行执行:

作为一个线程数量不受限制的示例,最多有三个并发线程来执行套件:parallel = all,useUnlimitedThreads = true,threadCountSuites = 3.

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.

这篇关于surefire-plugin不遵守threadCount参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆