surefire-plugin不尊重threadCount参数

时间:2015-07-17 14:28:22

标签: maven selenium selenium-webdriver junit maven-surefire-plugin

几天以后,我试着看看我的配置错误在哪里与我的Selenium测试并行运行。

我有一个有2个节点的Selenium Grid。 在我的pom.xml中,我已设置surefire以2比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 =&#39; TestAwesome&#39; 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>

1 个答案:

答案 0 :(得分:1)

由于您使用的是现代版本的surefire,您可能想尝试 threadCountMethods 参数而不是threadCount与 useUnlimitedThreads = true一起使用,即使看起来似乎反直觉。

surefire jUnit examples

  

从Surefire 2.7开始,使用并行的全套选项不需要额外的依赖关系。从Surefire 2.16开始,引入了新的线程计数属性,即threadCountSuites,threadCountClasses和 threadCountMethods

Fork options and parallel execution

  

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

相关问题