运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。

这次同时出现了两个问题,问题的场景是出现在启动测试类方法时出现的两个问题,第一个问题是版本问题,导致测试类无法被识别,并且测试类和测试方法前面出现红色叹号。解决方法是更改POM文件的对应内容导包即可;第二个问题是数据库不存在或者数据库的名称写错了,看数据库的名称是否正确,改过来就好了;

问题的详细描述和解决方法在下面,我自己感觉写的还算详细,对于刚开始学习的学弟们应该会有帮助,如果有解释不对的地方希望可以加我微信进行交流,我的quanminkj。

【开发工具IDEA】

【第一个问题提示】

六月 10, 2023 6:59:09 下午 org.junit.platform.launcher.core.DefaultLauncher handleThrowable
警告: 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运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。_第1张图片

。。。。。。。。中间隔了N行。。。。。。。

【第二个问题提示}

java.sql.SQLSyntaxErrorException: Unknown database 'store'

运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。_第2张图片

测试类前面出现红色的叹号运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。_第3张图片

 =========================================================================

【解决方法】

第一个问题的解决方法:更改POM配置文件的测试类部分,找到名称叫pom.xml的文件,找到与图片对应的部分,将原来的junit-vintage-engine (是 JUnit 4 中使用的测试引擎)改成junit-jupiter-engine( 是 JUnit 5 中使用的测试引擎),检查测试类中的导包名称是否正确,不正确的话将测试类上面的导包地址和注解删掉,再重写一遍注解并且导包即可。

改完记得保存文件,并且点击软件右下角弹出的提示,让资源下载到正确的位置。

【改之前的截图】

运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。_第4张图片

【改完后的截图】 运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。_第5张图片

【保存完POM文件后点击软件右下角的弹窗提示。】

运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。_第6张图片

找不到POM文件位置的可以看这里--------->> 

运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。_第7张图片

-------------------------------------------------------------------------------------------------------------------------------

第二个问题的解决方法是检查配置文件中数据库的名称是否写错,检查文件中的数据库名称与实际数据库的名称是否一致,也可能是出现忘记创建该名称的数据库的问题。

第一步找到名称叫application.properties文件,

运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。_第8张图片

 第二步找到数据库名称,改完保存即可。

运行测试类时出现错误,警告: TestEngine with ID ‘junit-vintage‘ failed to discover tests,找不到数据库,测试类前面出现红色叹号。_第9张图片

 解答完毕,欢迎点赞关注,更欢迎加微信进行交流学习。 quanminkj。

你可能感兴趣的:(junit,java,单元测试,mysql,数据库)