Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top