Arquillian - 运行测试不起作用

时间:2014-04-17 13:22:12

标签: java-ee jboss jboss-arquillian

我正在尝试添加基于arquillian的测试。当我mvn test时,我收到此错误:

测试:

@RunWith(Arquillian.class)
public class SomeEntityServiceTest extends ApiTestCase {
    @Inject
    CartStatusService service;

    @Test
    public void testCreate() throws Exception {
        SomeEntity someEntity = new SomeEntity();
        someEntity.setActive(1);

        service.create(someEntity);
    }
}

ApiTestCase:

public class ApiTestCase {

    @PersistenceContext(unitName = "myDataSource")
    protected EntityManager em;

    @Deployment
    public static Archive<?> createTestArchive() {
        WebArchive archive = ShrinkWrap.create(WebArchive.class, “my-service.war")
                .addPackages(true, "com.project")
                .addPackage(ApiTestCase.class.getPackage())
                .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
                .addAsWebInfResource("test-ds.xml", "test-ds.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

        return archive;
    }
}

Maven依赖:

    <dependency>
        <groupId>org.jboss.arquillian.junit</groupId>
        <artifactId>arquillian-junit-container</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

mvn clean test错误:

Running com.project.api.CartStatusServiceTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.275 sec <<< FAILURE! - in com.project.api.CartStatusServiceTest
com.project.api.CartStatusServiceTest  Time elapsed: 1.274 sec  <<< ERROR!
java.lang.RuntimeException: Could not create new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
    at org.jboss.arquillian.core.spi.Validate.notNull(Validate.java:44)
    at org.jboss.arquillian.container.impl.ContainerImpl.<init>(ContainerImpl.java:71)
    at org.jboss.arquillian.container.impl.LocalContainerRegistry.create(LocalContainerRegistry.java:76)
    at org.jboss.arquillian.container.impl.client.container.ContainerRegistryCreator.createRegistry(ContainerRegistryCreator.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:622)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
    at org.jboss.arquillian.core.impl.ManagerImpl.bindAndFire(ManagerImpl.java:236)
    at org.jboss.arquillian.core.impl.InstanceImpl.set(InstanceImpl.java:74)
    at org.jboss.arquillian.config.impl.extension.ConfigurationRegistrar.loadConfiguration(ConfigurationRegistrar.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:622)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
    at org.jboss.arquillian.core.impl.ManagerImpl.start(ManagerImpl.java:261)
    at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.<init>(EventTestRunnerAdaptor.java:56)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:534)
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:156)
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:111)
    at org.jboss.arquillian.test.spi.SecurityActions.newInstance(SecurityActions.java:97)
    at org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder.build(TestRunnerAdaptorBuilder.java:52)
    at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:93)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)


Results :

Tests in error: 
  JUnit4Provider.invoke:124->executeTestSet:153->execute:264 ? Runtime Could not...

1 个答案:

答案 0 :(得分:2)

您的maven依赖项仅列出JUnit和Arquillian JUnit。您还需要一个Arquillian容器来使用,以便执行您的测试。如果您实际上在类路径中有一个,请更新您的问题,否则请在其中一个Arquillian容器(例如JBoss,Tomcat等)上添加依赖项。