我正在尝试使用 io-rest-assure 为 Java 中的 Web 服务编写单元测试。自从我上次使用它以来,看起来发生了很大的变化。我收到错误 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;
或者导入类,并像往常一样调用静态方法:
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.*