【问题标题】:maven-surefire-plugin doesnot work in SpringBoot 2.2.2.RELEASE and abovemaven-surefire-plugin 在 Spring Boot 2.2.2.RELEASE 及更高版本中不起作用
【发布时间】:2020-07-17 09:50:54
【问题描述】:

我在我的 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 项目:

  • springBoot 2.2.6.RELEASE 模块不工作
  • 使用 springBoot 1.5.9.RELEASE 的工作模块
    除了 SprintBoot 版本之外,这两个模块都是相同的

【问题讨论】:

  • 你是从哪个版本的spring boot升级的? “测试停止运行..”是什么意思?您使用 junit/testng / JUnit Jupiter 哪个测试框架?查看完整的 pom 文件会有所帮助……以及构建的日志输出……
  • 您没有升级到最新的2.2.6.RELEASE 有什么原因吗?
  • 在 2.2.6.RELEASE 中它不能正常工作。
  • 太棒了。这有帮助。首先是 Spring Boot 1.5.X 仅使用 JUnit 4 ...spring-boot-starter-test 的传递依赖。 Spring boot 2.2.X 仅使用 JUnit Jupiter。在查看了那个项目后,我意识到 cucumber 似乎没有直接支持 JUnit Jupiter。仅支持 JUnit 4 (cucumber.io/docs/cucumber/api/#junit)。如果您在 JUnit Vintage 上运行并行化不起作用,因为 JUnit Vintage 不支持它。如果我正确理解黄瓜的文档,则仅支持 JUnit 4。这意味着如果你需要并行,你必须坚持使用 JUnit 4
  • 您好,我已经针对您的 git 存储库创建了一个拉取请求,该请求从 Spring 2.2X 项目中排除了 JUnit Jupiter 部门,并添加了 JUnit 4,这会导致像以前一样运行...

标签: maven unit-testing maven-surefire-plugin cucumber-junit parallel-testing


【解决方案1】:

在 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。

【讨论】:

    猜你喜欢
    • 2013-01-26
    • 2019-02-05
    • 1970-01-01
    • 2022-07-14
    • 1970-01-01
    • 2021-02-09
    • 2017-04-28
    • 2020-07-11
    • 2018-11-12
    相关资源
    最近更新 更多