import org.apache.commons.io.IOUtils;import org.junit.jupiter.api.Test;
import java.io.File;import java.io.FileInputStream;import java.io.IOException;
import static io.restassured.RestAssured.given;import static org.hamcrest.Matchers.equalTo;
public class TestAssertionXML { @Test void testXML() throws IOException {
// 定义请求体数据:源自文件对象 File file = new File("src/test/resources/add.xml"); FileInputStream fis = new FileInputStream(file); String reqBody = IOUtils.toString(fis, "UTF-8");
given() .contentType("text/xml") // 定制请求内容媒体类型 .body(reqBody) // 定制请求体数据 .when() .post("http://dneonline.com/calculator.asmx") // 发送请求 .then() .log().body() // 打印响应体信息 .body("//AddResult.text()", equalTo("2")); // 响应断言
}}
评论