我正在尝试将mockito添加到我的Arquillian测试中(使用ShrinkWrap),如下所示:
@Deployment
public static Archive<?> createDeployment() {
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar")
.addPackage(BeanClass.class.getPackage())
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
;
Archive[] libs = Maven.resolver()
.loadPomFromFile("pom.xml")
.resolve(
"org.mockito:mockito-all"
)
.withTransitivity()
.as(JavaArchive.class);
for (Archive lib : libs) {
archive = archive.merge(lib);
}
return archive;
}
我正在使用Mockito用
@Alternative
覆盖。但是,当我添加行archive = archive.merge(lib)
时,出现了异常:造成原因:java.lang.ClassNotFoundException:
org.apache.tools.ant.Task
不然我会得到
造成原因:java.lang.ClassNotFoundException:
org.mockito.asm.signature.SignatureVisitor
还有其他人也经历过吗?
更新:
一些额外的信息,我正在尝试使用Wildfly嵌入式容器对此进行测试:pom.xml
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-embedded</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-embedded</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-transaction-jta</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
最佳答案
我终于找到了所需的解决方案。我已经找到了包含蚂蚁依赖的解决方案。当我需要使用其他测试库(例如黄瓜)时,问题就开始了。
我现在正在使用EAR部署进行测试,该部署已解决了我的问题:
@Deployment
public static Archive<?> createDeployment() {
final JavaArchive ejbJar = ShrinkWrap
.create(JavaArchive.class, "ejb-jar.jar")
.addClass(NewSessionBean.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
final WebArchive testWar = ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(NewSessionBeanTest.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
;
Archive[] libsArchives = Maven.resolver()
.loadPomFromFile("pom.xml")
.resolve("org.mockito:mockito-all")
.withTransitivity()
.as(JavaArchive.class);
testWar.addAsLibraries(libsArchives);
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class)
.setApplicationXML("META-INF/test-application.xml")
.addAsModule(ejbJar)
.addAsModule(testWar);
return ear;
}
而我的
test-application.xml
<application>
<display-name>ear</display-name>
<module>
<ejb>ejb-jar.jar</ejb>
</module>
<module>
<web>
<web-uri>test.war</web-uri>
<context-root>/test</context-root>
</web>
</module>
</application>