2.2.6.RELEASE版本的springboot 单元测试报错 java.lang.NoClassDefFoundError: org/junit/platform/engine/support/

新建了一个2.2.6.RELEASE版本的springboot项目,在用单元测试的时候,发现没有@RunWith注解,于是,就添加了

 

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<scope>test</scope>

</dependency>

好,现在有这个注解了,运行测试方法,报错java.lang.NoClassDefFoundError: org/junit/platform/engine/support/filter/ExclusionReasonConsumingFilter
 

警告: TestEngine with ID 'junit-vintage' failed to discover tests

java.lang.NoClassDefFoundError: org/junit/platform/engine/support/filter/ExclusionReasonConsumingFilter

at org.junit.vintage.engine.discovery.VintageDiscoverer.createTestClassPredicate(VintageDiscoverer.java:83)

at org.junit.vintage.engine.discovery.VintageDiscoverer.collectTestClasses(VintageDiscoverer.java:61)

at org.junit.vintage.engine.discovery.VintageDiscoverer.discover(VintageDiscoverer.java:51)

at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:65)

at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130)

at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)

at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:82)

at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:48)

at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)

at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)

at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.support.filter.ExclusionReasonConsumingFilter

at java.net.URLClassLoader.findClass(URLClassLoader.java:382)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 11 more

其实实际原因是,这个版本的springboot此时默认的是JUnit5,而@RunWith是junit4里面的东西。解决方式有两种,要么你不要用这个@RunWith注解,要么你把pom文件里面的那个org.junit.vintage注释掉。

 

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

<!--<exclusions>-->

<!--<exclusion>-->

<!--<groupId>org.junit.vintage</groupId>-->

<!--<artifactId>junit-vintage-engine</artifactId>-->

<!--</exclusion>-->

<!--</exclusions>-->

</dependency>

完整代码可看

https://mp.csdn.net/console/editor/html/108922901

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值