【问题标题】:Migration from Junit 4 to Junit 5 - Test case are getting skipped从 Junit 4 迁移到 Junit 5 - 测试用例被跳过
【发布时间】:2018-10-16 07:04:34
【问题描述】:

我已将 junit 4 代码迁移到具有以下版本依赖项的 junit 5。

 <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.3.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-runner</artifactId>
        <version>1.3.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-junit-jupiter</artifactId>
        <version>2.22.0</version>
        <scope>test</scope>
    </dependency>

我的一个脚本使用命令

mvn -B verify -DforkCount=1 -DreuseForks=false

但是我面临的问题是在迁移到junit5之后运行它会跳过测试用例。

我正在使用maven-surefire-plugin - version 2.22.0.

运行时只打印下面一行

测试运行:0,失败:0,错误:0,跳过:0

我什至尝试了以下配置但没有帮助

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
        <configuration>
            <properties>
                <configurationParameters>
                    junit.jupiter.conditions.deactivate = *
                    junit.jupiter.extensions.autodetection.enabled = true
                    junit.jupiter.testinstance.lifecycle.default = per_class
                    junit.jupiter.execution.parallel.enabled = true
                </configurationParameters>
            </properties>
        </configuration>
    </plugin>
</plugins>

我的maven版本是3.3.9

并且不运行测试用例。我面临这个奇怪问题的任何具体原因。之前使用 JUnit 4 的相同测试用例运行良好。

经过进一步分析,我发现命令 => mvn -B verify -DforkCount=1 -DreuseForks=false 不运行测试用例并跳过它们。但是当我用 => mvn -B verify -DforkCount=1 -DreuseForks=true 替换相同的命令时,它开始工作。我了解属性 forkCount=1/reuseForks=true,这意味着 maven-surefire-plugin 创建了一个新的 JVM 进程来执行一个 Maven 模块中的所有测试,但想知道为什么它不能与 mvn -B verify -DforkCount=1 -DreuseForks=false 命令一起使用。 Junit5迁移是否需要任何maven或maven helper版本升级?

【问题讨论】:

  • 测试名称是什么?测试有一个命名约定,可能是这样的
  • mvn -B verify -DforkCount=1 -DreuseForks=true 有效,但 mvn -B verify -DforkCount=1 -DreuseForks=false 无效。只是想了解相同的任何具体原因。
  • @melanzane 这不是重复的。这是一个不同的具体问题 - 请参阅 my answer

标签: java maven junit4 maven-surefire-plugin junit5


【解决方案1】:

这是带有 JUnit 5.3[.1] 的 maven-surefire-plugin 中的 known bug 和使用分叉但不重用它们的配置。

升级到maven-surefire-plugin 2.22.1(上周末,2018 年 10 月 7 日发布)将解决该问题。

【讨论】:

  • 感谢@Mureinik 的回答。它解决了我的问题。你拯救了我的一天。也感谢大家的回复。
猜你喜欢
  • 2018-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-05
  • 1970-01-01
  • 2018-12-14
  • 2013-01-29
  • 2013-08-07
相关资源
最近更新 更多