java rest-assured的初步使用


rest-assured的官方文檔地址:
https://github.com/rest-assured/rest-assured/wiki/Usage#serialization

1、首先導入包 import static io.restassured.RestAssured.*; import io.restassured.response.ValidatableResponse; 2、無參的get請求,加結果輸出 ValidatableResponse result = when().get(url).then().statusCode(200); log.debug("get請求成功了{}", result.extract().asString()); 3、有參的get請求,加結果輸出 ValidatableResponse result = given().params(map). when().get(url).then().statusCode(200); log.debug("get請求成功了{}", result.extract().asString()); 4、json的post請求,加結果輸出(注意:參數是bogy) ValidatableResponse result= given(). contentType("application/json"). body(map). when(). post(url).then().statusCode(200); log.debug("get請求成功了{}", result.extract().asString()); 5、form-data的post請求,加結果輸出(注意:參數是params) ValidatableResponse result= given(). params(map1). when(). post(url).then().statusCode(200); log.debug("get請求成功了{}", result.extract().asString());

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM