我必须在我的应用程序中使用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
作为容器。
答案 0 :(得分:1)
没有任何解决方案,但有一些小建议:
remote
或managed
容器,因为它们更可靠。前者不会产生任何启动开销(当然一旦启动)@Deployment(testable = false)
和(testable = true)
之间的差异?.addPackages(true, "com.company.your_module")
PS。 this question看起来与你的相似。
希望它有所帮助