我正在尝试将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>
答案 0 :(得分:1)
我终于找到了我需要的解决方案。我找到了一个包含ant依赖的解决方案。当我需要使用像黄瓜这样的其他测试库时,问题就出现了。 我现在正在测试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>
答案 1 :(得分:0)
你无法使用Mockito进行静力学或决赛。
您需要使用PowerMock才能这样做。