代码之家  ›  专栏  ›  技术社区  ›  Pipo

java Junit4和JUnit5没有选择JUnit5测试

  •  0
  • Pipo  · 技术社区  · 4 年前

    我有一个工作环境,包括我无法管理的bom 未进行JUnit5测试 除非我导入 @Test 来自的测试方法的注释 import org.junit.Test; 如果我从中导入 import org.junit.jupiter.api.Test; 它们并没有被maven-surefire插件所接受。 我阅读了许多部分,并在一个较小的项目中进行了测试,以及它的工作和选择,我不知道该在这篇文章中包含什么,所以你有足够的信息来了解问题所在。 此外,如果有人能解释我读到的JUnit4和5都需要使用的导入的幕后原因,即

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit-jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <!--JUnit Jupiter Engine to depend on the JUnit4 engine and JUnit 4 API  -->
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>${junit-jupiter.version}</version>
        </dependency>
    

    带有版本

        <maven.surefire.version>3.0.0-M5</maven.surefire.version>
        <junit-jupiter.version>5.1.0</junit-jupiter.version>
    

    我很感激。

    请注意

    • 我的测试都在src/test/java/下。。。。。Java语言
    • 方法是公开的
    • 方法从测试开始
    • 类以Test结束
    0 回复  |  直到 4 年前
        1
  •  0
  •   Pipo    4 年前

    发现此依赖关系冲突,删除它解决了我的问题

        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-runner</artifactId>
            <version>1.8.2</version>
            <scope>test</scope>
        </dependency>
    

    还将spring引导依赖项版本更新为 2.6.6 ,有问题 2.3.3.RELEASE