我使用 Arquillian 集成测试框架运行测试。“Arquillian 不使用整个类路径来隔离测试存档。相反,它使用 ShrinkWrap 类,这是一个用于创建存档的 Java API。当我们创建要测试的存档时,我们指定要使用的类路径中包含哪些文件测试。在部署期间,ShrinkWrap 仅隔离测试所需的类”(Arquillian 测试简介)。
有我的配置:
@Deployment
public static WebArchive createDeployment() {
MavenResolverSystem resolver = Maven.resolver();
File[] files = resolver.loadPomFromFile("pom.xml").importRuntimeAndTestDependencies().resolve().withTransitivity().asFile();
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test.war");
webArchive.addAsLibraries(files)
.addClasses("There I add my classess")
.addAsManifestResource("arquillian/arquillian.xml");
System.out.println(webArchive.toString(true));
return webArchive;
}
和 pom.xml:
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-8</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
</dependency>
但我收到堆栈跟踪错误:
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive com.project.MyControllerTest.createDeployment()
Caused by: java.lang.IllegalArgumentException: No dependencies were set for resolution
INFO: Stopping service [arquillian-tomcat-embedded]
我错过了什么?