首页 > 解决方案 > maven-surefire-plugin 在 SpringBoot 2.2.2.RELEASE 及更高版本中不起作用

问题描述

我在我的 Maven 项目中使用了 maven-surefire-plugin 来并行执行测试。一切都很好。当我升级到 SpringBoot 2.2.2.RELEASE 及更高版本时,测试停止并行运行。这就是我使用插件的方式:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M4</version>
        <configuration>
            <parallel>methods</parallel>
            <useUnlimitedThreads>true</useUnlimitedThreads>
        </configuration>
    </plugin>

有没有办法并行执行测试?用这个插件?
我上传了一个包含两个模块的小型 Maven 项目:

标签: mavenunit-testingmaven-surefire-plugincucumber-junitparallel-testing

解决方案


在 pom 中创建配置:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <artifactId>junit-jupiter</artifactId>
                <groupId>org.junit.jupiter</groupId>
            </exclusion>
            <exclusion>
                <artifactId>junit-vintage-engine</artifactId>
                <groupId>org.junit.vintage</groupId>
            </exclusion>
            <exclusion>
                <artifactId>mockito-junit-jupiter</artifactId>
                <groupId>org.mockito</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13</version>
    </dependency>

这里的问题当然是您只使用 JUnit 4。


推荐阅读