如何让Maven Surefire运行所有类和测试?

时间:2018-04-30 02:39:10

标签: java maven testing junit maven-surefire-plugin

我有一个运行一些测试的Java JUnit Selenium测试框架。有两个类,每个类有两个测试。

我有像这样配置的maven surefire

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <forkCount>3</forkCount>
        <reuseForks>true</reuseForks>
        <parallel>methods</parallel>
        <threadCount>100</threadCount>
        <redirectTestOutputToFile>false</redirectTestOutputToFile>
    </configuration>
    <version>2.12.4</version>
</plugin>

我希望同时运行4个测试,但无论我使用threadCountparallelfork设置的组合,我只能获得1个等级值一次运行的测试用例。看起来这应该有效,任何人都可以提供解决方案吗?

3 个答案:

答案 0 :(得分:0)

您想要并行运行套件,还是并行运行方法或测试?

我找到并行运行套件的唯一可行解决方案是设置

<property>
   <name>suitethreadpoolsize</name>
   <value>8</value>
</property>
pom.xml中的

。其他所有组合都不起作用,因为我需要在同一个JVM上运行测试,而不是启动分叉进程。

答案 1 :(得分:0)

我在maven v2.20.1

中使用以下配置来确保v3.5.0
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven-surefire-plugin.version}</version>
    <configuration>
        <useUnlimitedThreads>true</useUnlimitedThreads>
        <rerunFailingTestsCount>1</rerunFailingTestsCount>
        <parallel>methods</parallel>
        <forkedProcessExitTimeoutInSeconds>2</forkedProcessExitTimeoutInSeconds>
    </configuration>
</plugin>

我相信这是有效的,因为我们的测试套件比以前快得多,并且windows报告正在运行的进程,特别是在运行surefire时会大大增加。

答案 2 :(得分:0)

可能对您来说晚了1年,但以防万一它可以帮助某人。

像您一样使用parallel = methods可以一次启动所有测试(方法),但是一次启动1个类(顺序)。因此,在您的示例中,有2个类具有2个测试,您将要执行ClassA的所有测试,然后是ClassB的所有测试。

如果要使用parallel = classes,则所有类都将同时启动,但是一次(顺序)运行1个测试(方法)。因此,在您的示例中,有两个具有2个测试的类,您将并行启动ClassA的Test1和ClassB的Test1,然后再执行ClassA的Test2和ClassB的Test2。

由于您希望所有4个测试并行执行,因此请使用parallel = all。 方法和类都将并行执行。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <parallel>all</parallel>
        <threadCount>10</threadCount>
    </configuration>
    <version>2.22.0</version>
</plugin>

注意:或者,您可能希望删除块,并将其设置为mvn命令行中的参数。 例如:mvn clean test -Dparallel = all -DthreadCount = 10

此致

相关问题