.RestAssured简介
REST Assured 是由 Johan Haleby开发和维护,当然这些年有很多人往这个github贡献过代码,使得这么这个工具越来越流行。
这个框架使java语言写接口测试用例变成和ruby和groovy语言一样容易和简单。
官方网站是:http://rest-assured.io/
官方文档:http://rest-assured.io/#docs
github项目地址:https://github.com/rest-assured/rest-assured
这个是这个框架的Logo, 下一篇我们创建一个maven项目,然后引用Rest-Assured框架。
相关链接:接口测试 rest-assured 使用指南_hualusiyu的专栏-CSDN博客_rest-assured
import io.restassured.RestAssured;
import io.restassured.path.xml.XmlPath;
import io.restassured.response.Response;
import org.apache.commons.io.IOUtils;
import java.io.FileInputStream;
public class TestSOAPAPI {
public String postMethod(String url, String requestPath,String filePath) throws Exception {
// put the request body in test.xml file.
FileInputStream fileInputStream = new FileInputStream(filePath);
RestAssured.baseURI = url;
Response response =
RestAssured.given()
.header("content-Type", "text/xml")
.and()
.body(IOUtils.toString(fileInputStream, "UTF-8"))
.when()
.post(requestPath)
.then()
.statusCode(200)
.and()
.log()
.all()
.extract()
.response();
XmlPath jsXpath = new XmlPath(response.asString()); // Converting string into xml path to assert
System.out.println(response.asString());
return response.asString();
}
}