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); } }
  • 相关阅读:
    面相对象2016/4/19
    2016/4/19
    ajax2016/4/15 post与get
    iframe2016/4/12
    Hibernate报错解决Error parsing JNDI name [],Need to specify class name
    vue-router 源码解析最简版
    vue数据响应式原理
    3-箭头函数与普通函数
    2.1.7 html的处理与打包
    2.1.6 css的编译与处理 -2
  • 原文地址:https://www.cnblogs.com/testertry/p/9903759.html
Copyright © 2011-2022 走看看