新手无法运行基本的单元测试

发布于 2024-11-15 21:46:19 字数 3666 浏览 4 评论 0原文

我正在尝试运行基本测试:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷荒 2024-11-22 21:46:19

巧合的是,我也试图为我的数据库测试选择unitils。我能够使用 Maven 2.2.1 复制您的问题。根据我之前使用 Maven 和 Hibernate 的工作经验以及站点文档,这些依赖项应该就是您所需要的。

如果有问题的话,很可能是hibernate相关的pom定义的问题,果然在unitils-orm的pom中,设置了如下的依赖为可选:

    <!-- Optional dependencies -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.5.ga</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.3.1.ga</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>concurrent</groupId>
        <artifactId>concurrent</artifactId>
        <version>1.3.4</version>
        <optional>true</optional>
    </dependency>

添加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:

    <!-- Optional dependencies -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.5.ga</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.3.1.ga</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>concurrent</groupId>
        <artifactId>concurrent</artifactId>
        <version>1.3.4</version>
        <optional>true</optional>
    </dependency>

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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文