我尝试使用“ ArquillianResteasyResource”在测试中注入WebTarget,但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有什么问题?
有任何想法吗 ?
最好的祝福
最佳答案
这个答案可能很晚,但是如果要在测试中插入webTarget
,则必须在测试方法中添加@RunAsClient
。
@Test
@Consumes(MediaType.APPLICATION_JSON)
@RunAsClient
public void testWithWT(@ArquillianResteasyResource WebTarget webTarget) {}