import static io.restassured.RestAssured.*;import org.junit.jupiter.api.Test;
import org.apache.commons.io.IOUtils;import java.io.File;import java.io.FileInputStream;import java.io.IOException;
public class TestXML { @Test void testSoapApi() 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) // 定制请求体数据 .log().headers() // 打印请求头信息 .log().body() // 打印请求体信息 .when() .post("http://dneonline.com//calculator.asmx") // 发送请求 .then() .statusCode(200); // 响应状态码断言 }}附录:IOUtils 依赖配置在 pom.xml中添加配置信息<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.11.0</version> <scope>test</scope></dependency>
评论