我正在尝试使用 io-rest-assured 为 Java 中的 Web 服务编写单元测试。自从我上次使用它以来,看起来发生了很多变化。我收到错误给定方法()未定义该类型
。我已经导入了我看来几乎所有必需的 jar 。有什么建议吗?我缺少什么?
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() 均未被识别。
最佳答案
对静态 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);
关于java - 该类型的给定方法()未定义 - http ://rest-assured. io/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49171005/