实现一个Post请求的测试case

右键example新建一个java类:PostExample

带参数的Post请求源码:
public class PostExample {

@BeforeClass

public void init(){

RestAssured.baseURI = “http://localhost:4567“;

RestAssured.basePath = “/login”;
}
@Test

public void postExampleTest(){

Response response = given().header(“”, “”).when().

param(“userName”, “weye”).

param(“pwd”,”123456”).

log().all().post(“”);

int resultCode = response.statusCode();

String result = response.getBody().print();

Assert.assertEquals(resultCode, 200, “返回码错误!”);

Assert.assertEquals(result,”验证通过,欢迎您:weye!”,”返回内容错误!”);
}
}

重点说明post请求的参数设置方法:
param(“userName”, “weye”).
param(“pwd”,”123456”).
注意:要跟在when的后面
运行case:
image.png
请求类型:post
请求参数:userName=weye
Pwd=123456

RestAssured接口系列|6 post请求的接口测试 - 图2