我正在尝试使用REST保证测试我的登录/注销功能。是否有可能有一个REST保证测试发布登录然后发布到注销?如果没有,我该如何正确测试?
你可以试试
expect().statusCode(HttpStatus.SC_OK)
.given()
.parameters("user", user, "password", URL)
.cookie("cookie_name", "cookie_value")
.post("/someURL");
还有一个确定的auth呼叫。
只需使用一个assert()/ expect()发送两个post():
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
import static com.jayway.restassured.RestAssured.*;
@Test
public void loginAndLogout(){
final String login = randomLogin();
// First post to login()
given()
.queryParam("login", login)
.queryParam("password", randomPassword())
.when().post("/login/");
// Second post to logout() with an assert
expect().statusCode(200)
.given()
.when().post("/logout/");
}
您的登录api调用是否会导致在后续请求中重用的某种身份验证令牌?如果是这样的话,我认为这些是单独的放心电话,可以完全测试它。
(登录焦点)
(退出焦点)
你试试这个:
使用xyzjson名称创建JSON文件,并将后有效内容数据保存在该文件中,并使用下面的代码。
Response rep = given()
.headers
.(headers)
.accept(contentType.json)
.body (xyzjson)
.when()
.post(someURL);
Assert.assertTrue(rep.StatusCode() == HttpStatus.SC_Ok);