我有这个测试
@Test
public void testInvalidLimitExceptionMapping() {
String errorMessage = "Invalid offset or limit values.";
String json = mapErrorToJson(errorMessage);
Mockito.when(orderService.getOrders(anyInt(), anyInt(), anyString()))
.thenThrow(new InvalidParameterException(errorMessage));
given()
.when().get("/v1/orders?offset=5&limit=10&date=2023-04-03")
.then()
.statusCode(400)
.body(is(json));
}
现在对端点进行身份验证后,它没有通过,我该如何处理身份验证部分?
RestAssured javadoc 有关于如何完成此操作的示例,请务必查看:https://www.javadoc.io/doc/io.rest-assured/rest-assured/latest/io/restassured/RestAssured .html
例如,您可以添加如下内容:
.auth().preemptive().basic("testUser", "testPassword")
进行测试 REST 调用设置。