2015-08-28 105 views
2

我尝试使用'ArquillianResteasyResource'在我的测试中注入WebTarget,但WebTarget的变量保持为空。(Arquillian REST扩展)为什么webtarget在测试方法中为null?

@Test 
@Consumes(MediaType.APPLICATION_JSON) 
public void testWithWT(@ArquillianResteasyResource WebTarget webTarget) { 
    ......} 

当我直接注入我的班级服务,一切工作正常!

@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问题?

有什么想法?

问候

+0

这是服务器端还是客户端测试?正在使用哪个版本的RestEasy? – LightGuard

+0

这是一个服务器端测试。我使用3.0.11.Final版本的RestEasy。 – Seb

+0

当然看起来像一个bug。 – LightGuard

回答

2

这个答案可能会晚点,但如果你要在测试中注入webTarget,你必须在测试方法中添加@RunAsClient

@Test 
@Consumes(MediaType.APPLICATION_JSON) 
@RunAsClient 
public void testWithWT(@ArquillianResteasyResource WebTarget webTarget) {} 
+0

这是正确的,但这并没有解决问题,我也出于某种原因得到WebTarget null – Lemmy4555

+0

这取决于你如何配置你的服务器以及如何启动测试,在服务器端ou客户端。如果你不提供更高的精度,我无法获得更多信息。我的答案不需要downvote – Dimitri

+0

正确的答案应该显示正确的pom.xml以正确地使用arquillian,然后正确的测试实现。 – Lemmy4555

相关问题