zoukankan      html  css  js  c++  java
  • 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); } }
  • 相关阅读:
    style实例
    背景小实例
    html表单与输入实例
    列表小知识
    表格的使用
    框架的奥秘
    链接那档子事
    判断网络是否连通
    Python3编码规范
    CentOS 7 安装 Docker-Compose
  • 原文地址:https://www.cnblogs.com/testertry/p/9903759.html
Copyright © 2011-2022 走看看