测试类运行失败:TestEngine with ID ‘junit-jupiter‘ failed to discover tests
背景:原本我的项目是可以运行的,然后我用另外一台电脑拉了下来,也是可以用的,但是很奇怪,用着用着就不能用了。报了以下错误:
/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=57098:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/shaonaiyi/.m2/repository/org/junit/platform/junit-platform-launcher/1.8.2/junit-platform-launcher-1.8.2.jar:/Users/shaonaiyi/.m2/repository/org/junit/platform/junit-platform-engine/1.8.2/junit-platform-engine-1.8.2.jar:/Users/shaonaiyi/.m2/repository/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:/Users/shaonaiyi/.m2/repository/org/junit/platform/junit-platform-commons/1.8.2/junit-platform-commons-1.8.2.jar:/Users/shaonaiyi/.m2/repository/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit5-rt.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/junit/lib/junit-rt.jar:/Users/shaonaiyi/IdeaProjects/mybatis-plus-learning/demo/target/test-classes:/Users/shaonaiyi/IdeaProjects/mybatis-plus-learning/demo/target/classes:/Users/shaonaiyi/app/mvn_repos/org/springframework/boot/spring-boot-starter/2.7.13/spring-boot-starter-2.7.13.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/boot/spring-boot/2.7.13/spring-boot-2.7.13.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/spring-context/5.3.28/spring-context-5.3.28.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/spring-aop/5.3.28/spring-aop-5.3.28.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/spring-beans/5.3.28/spring-beans-5.3.28.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/spring-expression/5.3.28/spring-expression-5.3.28.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/boot/spring-boot-autoconfigure/2.7.13/spring-boot-autoconfigure-2.7.13.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/boot/spring-boot-starter-logging/2.7.13/spring-boot-starter-logging-2.7.13.jar:/Users/shaonaiyi/app/mvn_repos/ch/qos/logback/logback-classic/1.2.12/logback-classic-1.2.12.jar:/Users/shaonaiyi/app/mvn_repos/ch/qos/logback/logback-core/1.2.12/logback-core-1.2.12.jar:/Users/shaonaiyi/app/mvn_repos/org/apache/logging/log4j/log4j-to-slf4j/2.17.2/log4j-to-slf4j-2.17.2.jar:/Users/shaonaiyi/app/mvn_repos/org/apache/logging/log4j/log4j-api/2.17.2/log4j-api-2.17.2.jar:/Users/shaonaiyi/app/mvn_repos/org/slf4j/jul-to-slf4j/1.7.36/jul-to-slf4j-1.7.36.jar:/Users/shaonaiyi/app/mvn_repos/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/spring-core/5.3.28/spring-core-5.3.28.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/spring-jcl/5.3.28/spring-jcl-5.3.28.jar:/Users/shaonaiyi/app/mvn_repos/org/yaml/snakeyaml/1.30/snakeyaml-1.30.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/boot/spring-boot-starter-test/2.7.13/spring-boot-starter-test-2.7.13.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/boot/spring-boot-test/2.7.13/spring-boot-test-2.7.13.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/boot/spring-boot-test-autoconfigure/2.7.13/spring-boot-test-autoconfigure-2.7.13.jar:/Users/shaonaiyi/app/mvn_repos/com/jayway/jsonpath/json-path/2.7.0/json-path-2.7.0.jar:/Users/shaonaiyi/app/mvn_repos/net/minidev/json-smart/2.4.11/json-smart-2.4.11.jar:/Users/shaonaiyi/app/mvn_repos/net/minidev/accessors-smart/2.4.11/accessors-smart-2.4.11.jar:/Users/shaonaiyi/app/mvn_repos/org/ow2/asm/asm/9.3/asm-9.3.jar:/Users/shaonaiyi/app/mvn_repos/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar:/Users/shaonaiyi/app/mvn_repos/jakarta/xml/bind/jakarta.xml.bind-api/2.3.3/jakarta.xml.bind-api-2.3.3.jar:/Users/shaonaiyi/app/mvn_repos/jakarta/activation/jakarta.activation-api/1.2.2/jakarta.activation-api-1.2.2.jar:/Users/shaonaiyi/app/mvn_repos/org/assertj/assertj-core/3.22.0/assertj-core-3.22.0.jar:/Users/shaonaiyi/app/mvn_repos/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar:/Users/shaonaiyi/app/mvn_repos/org/junit/jupiter/junit-jupiter/5.8.2/junit-jupiter-5.8.2.jar:/Users/shaonaiyi/app/mvn_repos/org/junit/jupiter/junit-jupiter-api/5.8.2/junit-jupiter-api-5.8.2.jar:/Users/shaonaiyi/app/mvn_repos/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar:/Users/shaonaiyi/app/mvn_repos/org/junit/platform/junit-platform-commons/1.8.2/junit-platform-commons-1.8.2.jar:/Users/shaonaiyi/app/mvn_repos/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar:/Users/shaonaiyi/app/mvn_repos/org/junit/jupiter/junit-jupiter-params/5.8.2/junit-jupiter-params-5.8.2.jar:/Users/shaonaiyi/app/mvn_repos/org/junit/jupiter/junit-jupiter-engine/5.8.2/junit-jupiter-engine-5.8.2.jar:/Users/shaonaiyi/app/mvn_repos/org/junit/platform/junit-platform-engine/1.8.2/junit-platform-engine-1.8.2.jar:/Users/shaonaiyi/app/mvn_repos/org/mockito/mockito-core/4.5.1/mockito-core-4.5.1.jar:/Users/shaonaiyi/app/mvn_repos/net/bytebuddy/byte-buddy/1.12.23/byte-buddy-1.12.23.jar:/Users/shaonaiyi/app/mvn_repos/net/bytebuddy/byte-buddy-agent/1.12.23/byte-buddy-agent-1.12.23.jar:/Users/shaonaiyi/app/mvn_repos/org/objenesis/objenesis/3.2/objenesis-3.2.jar:/Users/shaonaiyi/app/mvn_repos/org/mockito/mockito-junit-jupiter/4.5.1/mockito-junit-jupiter-4.5.1.jar:/Users/shaonaiyi/app/mvn_repos/org/skyscreamer/jsonassert/1.5.1/jsonassert-1.5.1.jar:/Users/shaonaiyi/app/mvn_repos/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/spring-test/5.3.28/spring-test-5.3.28.jar:/Users/shaonaiyi/app/mvn_repos/org/xmlunit/xmlunit-core/2.9.1/xmlunit-core-2.9.1.jar:/Users/shaonaiyi/app/mvn_repos/com/baomidou/mybatis-plus-boot-starter/3.5.1/mybatis-plus-boot-starter-3.5.1.jar:/Users/shaonaiyi/app/mvn_repos/com/baomidou/mybatis-plus/3.5.1/mybatis-plus-3.5.1.jar:/Users/shaonaiyi/app/mvn_repos/com/baomidou/mybatis-plus-extension/3.5.1/mybatis-plus-extension-3.5.1.jar:/Users/shaonaiyi/app/mvn_repos/com/baomidou/mybatis-plus-core/3.5.1/mybatis-plus-core-3.5.1.jar:/Users/shaonaiyi/app/mvn_repos/com/baomidou/mybatis-plus-annotation/3.5.1/mybatis-plus-annotation-3.5.1.jar:/Users/shaonaiyi/app/mvn_repos/com/github/jsqlparser/jsqlparser/4.3/jsqlparser-4.3.jar:/Users/shaonaiyi/app/mvn_repos/org/mybatis/mybatis/3.5.9/mybatis-3.5.9.jar:/Users/shaonaiyi/app/mvn_repos/org/mybatis/mybatis-spring/2.0.6/mybatis-spring-2.0.6.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/boot/spring-boot-starter-jdbc/2.7.13/spring-boot-starter-jdbc-2.7.13.jar:/Users/shaonaiyi/app/mvn_repos/com/zaxxer/HikariCP/4.0.3/HikariCP-4.0.3.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/spring-jdbc/5.3.28/spring-jdbc-5.3.28.jar:/Users/shaonaiyi/app/mvn_repos/org/springframework/spring-tx/5.3.28/spring-tx-5.3.28.jar:/Users/shaonaiyi/app/mvn_repos/org/projectlombok/lombok/1.18.28/lombok-1.18.28.jar:/Users/shaonaiyi/app/mvn_repos/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit5 com.shaonaiyi.demo.DemoApplicationTests,testSelectList
Internal Error occurred.
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:134)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:108)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:80)
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:110)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: org.junit.platform.commons.JUnitException: ClassSelector [className = 'com.shaonaiyi.demo.DemoApplicationTests'] resolution failed
at org.junit.platform.launcher.listeners.discovery.AbortOnFailureLauncherDiscoveryListener.selectorProcessed(AbortOnFailureLauncherDiscoveryListener.java:39)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:102)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.run(EngineDiscoveryRequestResolution.java:82)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolver.resolve(EngineDiscoveryRequestResolver.java:113)
at org.junit.jupiter.engine.discovery.DiscoverySelectorResolver.resolveSelectors(DiscoverySelectorResolver.java:46)
at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:69)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
... 13 more
Caused by: org.junit.platform.commons.PreconditionViolationException: Could not load class with name: com.shaonaiyi.demo.DemoApplicationTests
at org.junit.platform.engine.discovery.ClassSelector.lambda$getJavaClass$0(ClassSelector.java:75)
at org.junit.platform.commons.function.Try$Failure.getOrThrow(Try.java:335)
at org.junit.platform.engine.discovery.ClassSelector.getJavaClass(ClassSelector.java:74)
at org.junit.jupiter.engine.discovery.ClassSelectorResolver.resolve(ClassSelectorResolver.java:66)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.lambda$resolve$2(EngineDiscoveryRequestResolution.java:134)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1632)
at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:185)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolve(EngineDiscoveryRequestResolution.java:125)
at org.junit.platform.engine.support.discovery.EngineDiscoveryRequestResolution.resolveCompletely(EngineDiscoveryRequestResolution.java:91)
... 18 more
Caused by: java.lang.ClassNotFoundException: com.shaonaiyi.demo.DemoApplicationTests
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:527)
at org.junit.platform.commons.util.ReflectionUtils.lambda$tryToLoadClass$9(ReflectionUtils.java:829)
at org.junit.platform.commons.function.Try.lambda$call$0(Try.java:57)
at org.junit.platform.commons.function.Try.of(Try.java:93)
at org.junit.platform.commons.function.Try.call(Try.java:57)
at org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass(ReflectionUtils.java:792)
at org.junit.platform.commons.util.ReflectionUtils.tryToLoadClass(ReflectionUtils.java:748)
... 33 more
网上的很多方法都试过了,什么加依赖,排除依赖之类的,但是其实这样的错误,不应该关心项目本身的问题,因为它在另外一台电脑是可以跑的,所以考虑的话可以考虑环境,比如Maven版本、配置、依赖之类的。
最终解决办法:在IDEA中操作一下就可以了,先mvn clean一下Maven依赖,然后再mvn install一下,注意,一定要install,只clean是不行的。
但是,又发现了一个新的问题,测试时,只能新增、查看,不能删除和修改😂😂😂…
尝试加上@Rollback(false),也不生效,删除时影响行数是0,修改时影响行数是1,但结果就是不一样。