本章讲解rest-assured自带的全局请求地址配置,方便管理
1、在pox.xml文件在导入rest-assured依赖
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
2、在@Test注解标注的方法之前执行配置的参数就行了。比如@BeforeSuite,当然使用其他的也可以
@BeforeSuite
public void before() {
RestAssured.baseURI = "http://localhost:9000";
}
3、如果@BeforeSuite和@Test注解的方法不在同一个类中,@Test注解的方法的类需要继承@BeforeSuite所在类
4、在使用post、get等其他请求是地址就不需要写http://localhost:9000,只需要写后面的就可以了
given().log().all()
.headers(jsonTurnMap(caseInfo.getHeaders()))
.when()
.body(jsonTurnMap(caseInfo.getParams()))
.post("test/test")
.then().log().all()