方法 given() 未定义类型 - http://rest-assured.io/

The method given() is undefined for the type - http://rest-assured.io/

我正在尝试使用 io-rest-assured 在 Java 中为 Web 服务编写单元测试。看起来自从我上次使用它以来发生了很多变化。我收到错误 The method given() is undefined for the type。在我看来,我已经导入了几乎所有需要的罐子。我缺少什么有什么建议吗?

import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import io.restassured.RestAssured.*;
import io.restassured.matcher.RestAssuredMatchers.*;
import org.hamcrest.Matchers.*;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
import io.restassured.module.jsv.JsonSchemaValidator.*;
import io.restassured.module.mockmvc.RestAssuredMockMvc.*;

public class ProxyIntegrationTest_RA extends MockControllerIntegrationTest{

    private static final String REQUEST_MAPPING = "/xy/v1/fax";

    @Test
    public void testGetServices_success() throws Exception {
        final String niv = "1234567890";

        given().
            param("store","0123").
        when().
            get(REQUEST_MAPPING + "/vehicles/{niv}/serviceHistory", niv).
        then().
            statusCode(200);
    }
}

given(), when(), then() none 被识别。

为静态 given() 方法使用静态导入:

    import static io.restassured.matcher.RestAssuredMatchers.given;

或者导入class,照常调用静态方法:

    import io.restassured.matcher.RestAssuredMatchers;

...

    RestAssuredMatchers.given().
        param("store","0123").
    when().
        get(REQUEST_MAPPING + "/vehicles/{niv}/serviceHistory", niv).
    then().
        statusCode(200);

我遇到了与 apun 相同的问题,但 Arnaud 的回答没有修复错误。

对我来说,添加这个导入有效:

import static io.restassured.RestAssured.given;

我遇到了同样的问题,但使用了下面的行

import static io.restassured.RestAssured.*