与 maven surefire 插件并行运行测试

Chr*_*ris 5 java testing automated-tests maven-3 maven-surefire-plugin

最近得到了一份新工作,我在做一个 Maven 和 Micronaut 项目——我是 Micronaut 的新手,如果你不熟悉,它是 Spring 的替代品。

以此为指导:https : //www.baeldung.com/maven-junit-parallel-tests

我试图让我们的集成测试并行运行,以加速我们的测试。我已将所需的配置添加到 pom.xml 文件中。我已经调整了很多,使用不同的设置组合(包括我在其他 SO 帖子中找到的设置)。

但是当我运行测试时,无论有没有添加这个配置,运行它们所需的时间都是一样的——1 分 38 秒。所以我认为它不起作用。虽然不知道我在控制台上的预期输出应该是什么样子,如果它正常工作?

在测试中,他们都没有使用@RunWith,它使用默认值,应该没问题。

这是pom。任何人都可以请指教吗?谢谢。

<profiles>
    <profile>
      <id>integration</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludedGroups>unit, performance</excludedGroups>
              <parallel>classes</parallel>
              <threadCount>10</threadCount>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>performance</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludedGroups>unit, integration</excludedGroups>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>all</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <excludedGroups>none</excludedGroups>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
Run Code Online (Sandbox Code Playgroud)
<build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
        <configuration>
          <excludedGroups>integration, performance</excludedGroups>
          <parallel>classes</parallel>
          <threadCount>10</threadCount>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
Run Code Online (Sandbox Code Playgroud)

小智 3

我遇到了同样的问题并尝试了以下每种组合:

  1. maven-surefire-插件(版本 2.22.0)

  2. maven-failsafe-plugin(版本 2.22.0)

    • 这是另一个基本相同的插件,但设计用于运行集成测试,因为它在第一次失败的测试后不会停止。
  3. 您提到的并行/线程计数配置。

  4. 这些不同的插件配置在https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven-config-paramshttps://junit.org/junit5/docs/current中指定/用户指南/#writing-tests-parallel-execution。就像这样:

       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-failsafe-plugin</artifactId>
         <version>2.22.0</version>
         <configuration>
           <properties>
             <configurationParameters>
               junit.jupiter.execution.parallel.enabled=true
               junit.jupiter.execution.parallel.mode.default=same_thread
               junit.jupiter.execution.parallel.mode.classes.default=concurrent
             </configurationParameters>
           </properties>
         </configuration>
      </plugin>
    
    Run Code Online (Sandbox Code Playgroud)

唯一有效的组合是 2 (maven-failsafe-plugin) 和 4 (configurationParameters)。