restAssured + TestNG测试接口,以下是一个get 请求。

用restAssured 和 TestNG 进行一个get 接口的接口测试。

package Elaine.Test.G.APITest;

import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.restassured.response.Response;
import static io.restassured.RestAssured.*;
import static io.restassured.matcher.RestAssuredMatchers.*;
import static io.restassured.path.json.JsonPath.from;
import static org.hamcrest.Matchers.*;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.module.jsv.JsonSchemaValidator.*;
public class Get {
private Response response;
Map
<String, Object> map = new HashMap<String, Object>(); int statuscode; @Test public void f() { map.put("startDt", "2017-04-01"); map.put("enddt", "2019-05-24"); response = given().params(map).get("http://www.fakehost.com/api/v1/fakeurl"); statuscode = response.getStatusCode(); System.out.println(statuscode); if(statuscode != 200){ throw new AssertionError("status code is" + statuscode + "by mistake"); } //以下的code 是为了打印出来看所有的返回值的。不参与测试过程 String message = response.jsonPath().getString("Message"); System.out.println(message); System.out.println(map); map = null; System.out.println(map); } }

 

posted @ 2018-11-18 21:37  Elaine_Septer  阅读(1341)  评论(0编辑  收藏  举报