JUnit和Surefire并行测试 - ForkCount和ThreadCount

use*_*od2 12 java parallel-processing junit selenium surefire

我正在使用Surefire插件在Selenium Grid上运行Selenium测试来执行测试.就我的测试分类而言,我有几个类,其中一些有1个测试,还有一个多个测试.

所以在我的网格上我有30个chrome web驱动程序,我想并行执行所有类中的所有测试.

我已经阅读了如何使用parallel我设置的参数执行此操作:

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <includes>
                        <include>${testSuite}</include>
                    </includes>
                    <parallel>all</parallel>
                    <useSystemClassLoader>false</useSystemClassLoader>
                    <perCoreThreadCount>false</perCoreThreadCount>
                    <threadCount>20</threadCount>
                    <browser>${browser_type}</browser>
                </configuration>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

但是,这似乎并没有填补我可用的所有Chrome网络驱动程序.

如果我然后使用forkCount,如:

<forkCount>20</forkCount>
<reuseForks>true</reuseForks>
Run Code Online (Sandbox Code Playgroud)

然后,当测试执行首次启动时,所有Web驱动程序都会被填充,但它会快速开始丢弃并一次执行一个.

所以我的问题:

  • forkCount和threadCount之间是否存在关系
  • 还有什么我需要做的才能让它并行运行吗?

谢谢.

urs*_*rsa 4

您必须提供显式的 junit 测试提供程序:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-junit47</artifactId>
            <version>2.18.1</version>
        </dependency>
    </dependencies>
    <configuration>
        <parallel>all</parallel>
        <useUnlimitedThreads>true</useUnlimitedThreads>
        <useSystemClassLoader>false</useSystemClassLoader>
        <includes>
            <include>${testSuite}</include>
        </includes>
        <systemPropertyVariables>
            <browser>${browser_type}</browser>
        </systemPropertyVariables>
     </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

您应该使用 JUnit 4.7+,因为旧版本无法正确进行并行测试。

如果您的测试不影响 JVM 运行时(通常情况并非如此),您还可以省略与 fork 相关的参数。

或者将您的测试迁移到 TestNG - 它是更优雅的框架,并且它可以更好地进行并行测试,然后是 JUnit (imo)。