无法使用Arquillian运行多个测试

时间:2014-12-17 09:53:24

标签: java maven java-ee wildfly jboss-arquillian

我必须在我的应用程序中使用Arquillian测试单元,每个测试单元都有自己的部署方法:

@RunWith(Arquillian.class)
public class CallerTest {
    @EJB
    private CallerPrincipalDemoSessionBean sut;

    @Deployment
    public static WebArchive createTestArchive1() {
        WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test1.war")
                .addClasses(JBossLoginContextFactory.class, CallerPrincipalDemoSessionBean.class)
                .addAsWebInfResource("META-INF/ejb-jar.xml")
                .addAsWebInfResource("META-INF/jboss-ejb3.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
                .addAsResource("users.properties")
                .addAsResource("roles.properties");
        return webArchive;
    }

    ...

和第二个:

@RunWith(Arquillian.class)
public class UsersTest {

    @ArquillianResource
    private URL serverUrl;

    @Deployment(testable = false)
    public static Archive createTestArchive2() {
        return ShrinkWrap.create(WebArchive.class, "test2.war")
                .addPackage(User.class.getPackage())
                .addPackage(UserFacade.class.getPackage())
                .addPackage(Users.class.getPackage())
                .addPackage(Credential.class.getPackage())
                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                .setWebXML(new File("src/test/resources/test-web.xml"))
                .addAsWebInfResource("META-INF/jboss-web.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
                .addAsResource("users.properties")
                .addAsResource("roles.properties");
    }

    ...

当我删除其中一个类或评论其中一个" @ Deployment"方法mvn test非常完美。但是使用2" @ Deployment"方法甚至用mvn test -Dtest=com.wpic.tmall.rest.UsersTest测试单个类引发异常:

ERROR [org.jboss.msc.service.fail] MSC000001: Failed to start service jboss.deployment.unit."test2.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."test2.war".WeldStartService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_05]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_05]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_05]
Caused by: org.jboss.weld.exceptions.DeploymentException: org/jboss/shrinkwrap/api/asset/Asset
    at org.jboss.weld.executor.AbstractExecutorServices.checkForExceptions(AbstractExecutorServices.java:66)
    at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:43)
    at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:51)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer.createClassBeans(ConcurrentBeanDeployer.java:72)
    at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:260)
    at org.jboss.weld.bootstrap.WeldStartup.deployBeans(WeldStartup.java:351)
    at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:79)
    at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:92)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    ... 3 more
Caused by: java.lang.NoClassDefFoundError: org/jboss/shrinkwrap/api/asset/Asset
    at java.lang.Class.getDeclaredMethods0(Native Method) [rt.jar:1.8.0_05]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2688) [rt.jar:1.8.0_05]
    at java.lang.Class.getDeclaredMethods(Class.java:1962) [rt.jar:1.8.0_05]
    at java.lang.Class.getEnclosingMethod(Class.java:1032) [rt.jar:1.8.0_05]
    at org.jboss.weld.util.reflection.Reflections.isNonStaticInnerClass(Reflections.java:388)
    at org.jboss.weld.util.Beans.isTypeManagedBeanOrDecoratorOrInterceptor(Beans.java:486)
    at org.jboss.weld.bootstrap.BeanDeployer.createClassBean(BeanDeployer.java:233)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:74)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:72)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_05]
    ... 3 more
Caused by: java.lang.ClassNotFoundException: org.jboss.shrinkwrap.api.asset.Asset from [Module "deployment.test2.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules-1.3.3.Final.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules-1.3.3.Final.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules-1.3.3.Final.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules-1.3.3.Final.jar:1.3.3.Final]
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules-1.3.3.Final.jar:1.3.3.Final]
    ... 15 more

我正在使用wildfly-arquillian-container-embedded版本8.1.0.Final作为容器。

1 个答案:

答案 0 :(得分:1)

没有任何解决方案,但有一些小建议:

  • 最好的办法是在看Arquillian时忽略你的IDE一分钟。首先:确保您使用maven(而不是来自IDE)启动测试
  • 小心嵌入式容器。如果我是你,我会切换到remotemanaged容器,因为它们更可靠。前者不会产生任何启动开销(当然一旦启动)
  • 您是否了解@Deployment(testable = false)(testable = true)之间的差异?
  • 确保您没有遗漏部署档案中的任何所需类。为了使其成为现实,我喜欢通过.addPackages(true, "com.company.your_module")
  • 进行递归添加
  • 如果没有任何帮助,那么你可以尝试不同的远程容器,如:JBoss AS 7.1.1,Wildfly 8.0.0

PS。 this question看起来与你的相似。

希望它有所帮助