1. 程式人生 > >restAssured 測試接口,以下是一個get 請求。

restAssured 測試接口,以下是一個get 請求。

ash module ret stat system print java .get sco

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;

@BeforeTest
public void beforeTest() {

}

@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);
}

}

restAssured 測試接口,以下是一個get 請求。