新手无法运行基本的单元测试
我正在尝试运行基本测试:
import org.junit.Test;
import org.unitils.UnitilsJUnit4;
public class SampleUnitilsTest extends UnitilsJUnit4 {
@Test
public void testTest() {
assertTrue(true);
}
}
但我得到以下堆栈跟踪:
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.getUnitils(UnitilsJUnit4TestClassRunner.java:214)
at org.unitils.UnitilsJUnit4TestClassRunner.getTestListener(UnitilsJUnit4TestClassRunner.java:204)
at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:67)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.unitils.core.UnitilsException: Could not load class with name org.hibernate.cfg.AnnotationConfiguration
at org.unitils.util.ReflectionUtils.getClassWithName(ReflectionUtils.java:482)
at org.unitils.orm.hibernate.HibernateModule.init(HibernateModule.java:86)
at org.unitils.core.ModulesLoader.createAndInitializeModules(ModulesLoader.java:151)
... 15 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfiguration
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.unitils.util.ReflectionUtils.getClassWithName(ReflectionUtils.java:479)
... 17 more
我的 POM 包括以下内容:
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-core</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-dbunit</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-orm</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
如果重要的话,我会在 Eclipse Helios SR2 JUnit 4 测试器中执行此操作。有什么想法吗?
I'm trying to run a basic test:
import org.junit.Test;
import org.unitils.UnitilsJUnit4;
public class SampleUnitilsTest extends UnitilsJUnit4 {
@Test
public void testTest() {
assertTrue(true);
}
}
But I am getting the following stack trace:
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.getUnitils(UnitilsJUnit4TestClassRunner.java:214)
at org.unitils.UnitilsJUnit4TestClassRunner.getTestListener(UnitilsJUnit4TestClassRunner.java:204)
at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:67)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.unitils.core.UnitilsException: Could not load class with name org.hibernate.cfg.AnnotationConfiguration
at org.unitils.util.ReflectionUtils.getClassWithName(ReflectionUtils.java:482)
at org.unitils.orm.hibernate.HibernateModule.init(HibernateModule.java:86)
at org.unitils.core.ModulesLoader.createAndInitializeModules(ModulesLoader.java:151)
... 15 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfiguration
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.unitils.util.ReflectionUtils.getClassWithName(ReflectionUtils.java:479)
... 17 more
My POM includes the following:
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-core</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-dbunit</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-orm</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>
If it matters, I'm doing this within Eclipse Helios SR2 JUnit 4 tester. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
巧合的是,我也试图为我的数据库测试选择unitils。我能够使用 Maven 2.2.1 复制您的问题。根据我之前使用 Maven 和 Hibernate 的工作经验以及站点文档,这些依赖项应该就是您所需要的。
如果有问题的话,很可能是hibernate相关的pom定义的问题,果然在unitils-orm的pom中,设置了如下的依赖为可选:
添加hibernate-entitymanager确实解决了问题 至于为什么会这样如此定义,任何有效的理由都只有开发人员知道。
Coincidentally, I was trying to pick up unitils for my db testing as well. I was able to replicate your problem with maven 2.2.1. From my prior working experience with maven and hibernate, and the site documentation, those dependencies should be all that you need.
If there is any problem, it probably lies with the pom definitions related to hibernate, and sure enough in the pom for unitils-orm, the following dependencies are set as optional:
Adding hibernate-entitymanager did resolve the problem As for whether why that pom is defined as such, any valid reasons would only be known to the developers..