概述
1、单元测试无法启动报错:IDEA 无法运行Junit, 报错Class not found xxxx Empty test suite. 找不到类
查看project Structure---Modules----Paths----选择Use module compile output path,若无法保存,将中间列的多余部分删除即可。
查看project Structure---Modules----Paths----选择Use module compile output path,若无法保存,将中间列的多余部分删除即可。
2、单元测试junit报错:
org.unitils.core.UnitilsException: An exception occured during the loading of core module hibernate with module class name org.unitils.orm.hibernate.HibernateModule
at org.unitils.core.ModulesLoader.createAndInitializeModules(ModulesLoader.java:154)
at org.unitils.core.ModulesLoader.loadModules(ModulesLoader.java:121)
at org.unitils.core.Unitils.createModulesRepository(Unitils.java:222)
at org.unitils.core.Unitils.init(Unitils.java:118)
at org.unitils.core.Unitils.init(Unitils.java:105)
at org.unitils.core.Unitils.initSingletonInstance(Unitils.java:74)
at org.unitils.core.Unitils.getInstance(Unitils.java:52)
at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:64)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
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: org.unitils.core.UnitilsException: Could not load class with name org.hibernate.cfg.AnnotationConfiguration
at org.unitils.util.ReflectionUtils.getClassWithName(ReflectionUtils.java:612)
at org.unitils.orm.hibernate.HibernateModule.init(HibernateModule.java:91)
at org.unitils.core.ModulesLoader.createAndInitializeModules(ModulesLoader.java:151)
... 12 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfiguration
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.unitils.util.ReflectionUtils.getClassWithName(ReflectionUtils.java:609)
... 14 more
org.unitils.core.UnitilsException: An exception occured during the loading of core module hibernate with module class name org.unitils.orm.hibernate.HibernateModule
at org.unitils.core.ModulesLoader.createAndInitializeModules(ModulesLoader.java:154)
at org.unitils.core.ModulesLoader.loadModules(ModulesLoader.java:121)
at org.unitils.core.Unitils.createModulesRepository(Unitils.java:222)
at org.unitils.core.Unitils.init(Unitils.java:118)
at org.unitils.core.Unitils.init(Unitils.java:105)
at org.unitils.core.Unitils.initSingletonInstance(Unitils.java:74)
at org.unitils.core.Unitils.getInstance(Unitils.java:52)
at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:64)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
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: org.unitils.core.UnitilsException: Could not load class with name org.hibernate.cfg.AnnotationConfiguration
at org.unitils.util.ReflectionUtils.getClassWithName(ReflectionUtils.java:612)
at org.unitils.orm.hibernate.HibernateModule.init(HibernateModule.java:91)
at org.unitils.core.ModulesLoader.createAndInitializeModules(ModulesLoader.java:151)
... 12 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfiguration
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.unitils.util.ReflectionUtils.getClassWithName(ReflectionUtils.java:609)
... 14 more
解决方案:先尝试删除pom.xml中的依赖
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-orm</artifactId>
<version>3.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-orm</artifactId>
<version>3.4.2</version>
<scope>test</scope>
</dependency>
错误换了,找不到加载的text-spring.xml、test-spring-mybatis.xml、test-spring-mvc.xml、test-spring-aop.xml文件,打不开
打开IDEA的Project Structure---Modules----点开右边的项目,查看src---test---resource有没有为空,对比java中的resource,如果为空可以选择上面的Mark as
把它标记为Resources
打开IDEA的Project Structure---Modules----点开右边的项目,查看src---test---resource有没有为空,对比java中的resource,如果为空可以选择上面的Mark as
把它标记为Resources
最后
以上就是标致摩托为你收集整理的单元测试Junit的全部内容,希望文章能够帮你解决单元测试Junit所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复