SpringBoot单元测试失败,报错Invalid test class 'com.qfedu.tkmapperdemo.dao.UserDAOTest'

SpringBoot单元测试失败,报错Invalid test class 'com.qfedu.tkmapperdemo.dao.UserDAOTest'

 

错误代码:

org.junit.runners.model.InvalidTestClassError: Invalid test class 'com.qfedu.tkmapperdemo.dao.UserDAOTest':
  1. The class com.qfedu.tkmapperdemo.dao.UserDAOTest is not public.
  2. Test class should have exactly one public constructor

    at org.junit.runners.ParentRunner.validate(ParentRunner.java:525)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:92)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:74)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:137)
    at org.springframework.test.context.junit4.SpringRunner.<init>(SpringRunner.java:49)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
    at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)


Process finished with exit code -1

而且测试类的@Test旁边没有启动小三角。

 

解决方法:

1.检查Test是否导错,应该使用org.junit.Test

 

 

 

2.(我的问题)检查类是否用public修饰,检查测试方法是否用public修饰。

 

 

 

 添加public后,测试类正常运行!

 

 

 

 

感谢:https://blog.csdn.net/qq_25844803/article/details/107790039

 
posted @ 2022-06-22 15:26  临易  阅读(299)  评论(0编辑  收藏  举报