java - (Arquillian REST 扩展)为什么 webtarget 在测试方法中为空?

标签 java rest junit resteasy jboss-arquillian

我尝试使用“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/

相关文章:

java - MockMvc - 使用复杂对象调用查询

java - 有没有办法指示字符串模型属性在 Swagger 中具有最大长度?

java - Spring API 中的日志请求和响应

gradle - 如何在 Gradle 中使用 JUnit 5 控制台启动器标志

java - 在所选项目中找不到测试类

java - 如何在具有多个测试的 JUnit 类中为特定测试运行tearDown 类型方法?

java - Spring MVC在jsp页面导入css和js

java - 匹配java中的字符串模式

java - 在 intellij 中为 hibernate 使用构建 gradle

java - 为什么在我的 IDE 中找不到 javafx.mail.jar Java 库?