JUnit 5迁移-如何解决java.lang.ClassNotFoundException:org.unit.jupi



当我运行一些JUnit 5测试时(同一项目中也有JUnit 4测试,因为我们正在向JUnit 5迁移(,我看到了以下错误:

No tests were executed
...
Caused by:
java.lang.ClassNotFoundException: org.junit.jupiter.api.extension.ReflectiveInvocationContext

如何解决?

确保pom.xml:中有这些依赖项

  • org.junit.jupiter:junitjupiter引擎

对于JUnit 4:

  • junit:4.12+
  • org.junit.vvintage:junit-vvintage引擎(仅支持JUnit4.12+(

如果您想使用@ParameterizedTest:

  • org.junit.jupiter:junitjupiterapi
  • org.junit.jupiter:junitjupiter参数

org.junit.platform:junit-platform-launcher是不需要的,即使您想在Intellij中运行测试也是如此。也许你可以不带它试试。

<!-- junit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<!-- junit 5 parameterized tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<!-- for compatibility for JUnit 4. JUnit vintage needs 4.12+ -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- for compatibility for JUnit 4 -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<!-- for IDE support only(running tests from IDE) -->
<!--        <dependency>-->
<!--            <groupId>org.junit.platform</groupId>-->
<!--            <artifactId>junit-platform-launcher</artifactId>-->
<!--            <version>1.7.1</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->

最新更新