我尝试使用“ArquillianResteasyResource”在我的测试中注入(inject) WebTarget,但 WebTarget 的变量仍然为空。
@Test
@Consumes(MediaType.APPLICATION_JSON)
public void testWithWT(@ArquillianResteasyResource WebTarget webTarget) {
......}
当我直接注入(inject)我的类服务时,一切正常!
@Test
@Consumes(MediaType.APPLICATION_JSON)
public void testWithWT(@ArquillianResteasyResource MyService sv) {
......}
我的 pom 依赖:
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.eu.ingwar.tools</groupId> <artifactId>arquillian-suite-extension</artifactId> <version>1.1.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.junit</groupId> <artifactId>arquillian-junit-container</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.wildfly.arquillian</groupId> <artifactId>wildfly-arquillian-container-embedded</artifactId> <version>1.0.1.Final</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-rest-client-api</artifactId> <version>1.0.0.Alpha3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-rest-client-impl-3x</artifactId> <version>1.0.0.Alpha3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.wildfly</groupId> <artifactId>wildfly-embedded</artifactId> <version>9.0.0.Final</version> <scope>test</scope> </dependency>
WebTarget 有什么问题?
有什么想法吗?
最好的问候
最佳答案
这个答案可能会迟到,但是如果你想在测试中注入(inject) webTarget
,你必须在测试方法中添加 @RunAsClient
。
@Test
@Consumes(MediaType.APPLICATION_JSON)
@RunAsClient
public void testWithWT(@ArquillianResteasyResource WebTarget webTarget) {}
关于java - (Arquillian REST 扩展)为什么 webtarget 在测试方法中为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32265740/