【问题标题】:Spring Boot - Rest Assured methods not foundSpring Boot - 找不到放心的方法
【发布时间】:2016-05-22 07:26:48
【问题描述】:

我有一个使用 Spring Boot 构建的 REST API。

我正在尝试使用 Rest-Assured 测试框架,但我似乎无法让它工作。

我正在使用来自Here的指南

get("/lotto").then().assertThat().body("lotto.lottoId", equalTo(5));

并已将依赖项添加到我的 maven 项目中。

<dependency>
      <groupId>com.jayway.restassured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>2.9.0</version>
      <scope>test</scope>
</dependency>

但是,它似乎没有导入所需的类,只是提示我创建一个新的“get()" 方法。

我的测试课:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
@WebIntegrationTest
public class DemoControllerTest  {

    @Test
    public void test() {
        get("/lotto").then().assertThat().body("lotto.lottoId", equalTo(5));
    }

}

我错过了什么?

【问题讨论】:

  • 不太了解放心。但是在 Java 类中不应该有导入来使用这些方法。
  • 我正在使用 eclipse 来管理导入。它没有任何建议。

标签: java spring testing spring-boot rest-assured


【解决方案1】:

我错过了什么?

一个简单的static 导入,不见了!为了解析get静态方法,只需使用下面的static import:

import static com.jayway.restassured.RestAssured.get;

【讨论】:

  • 该死,我不应该这么依赖 IDE。现在工作。
【解决方案2】:

我有类似的问题。我做了什么(使用新版本 3.0.2):

import io.restassured.RestAssured.*;
import io.restassured.matcher.RestAssuredMatchers.*;
import org.hamcrest.Matchers.*;

代替:

import static io.restassured.RestAssured.*;
import static io.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;

所以我有同样的问题找不到方法...

【讨论】:

    猜你喜欢
    • 2020-09-19
    • 2021-05-07
    • 2017-03-31
    • 2020-03-07
    • 1970-01-01
    • 2020-07-31
    • 2020-11-11
    • 2017-10-11
    • 2021-03-14
    相关资源
    最近更新 更多