配置MAVEN

        <dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
</dependency>

发送json请求1:

    RequestSpecification request = RestAssured.given().header("Content-Type", "application/json");
JSONObject requestParams = new JSONObject();
JSONObject childObject1= new JSONObject();
JSONObject childObject2 = new JSONObject();
requestParams.put("contactClass", "ZWSS");
requestParams.put("contactActivity", "0039");
requestParams.put("contractAccountNumber", "210024144291");
requestParams.put("text", "Please rate the overall ease of using the website to initiate or make your service request");
requestParams.put("contactType", "Z1");
requestParams.put("contactDirection", "1"); childObject1.put("question", "0001");
childObject1.put("answer", "01");
childObject1.put("question", "0002");
childObject1.put("answer", "02"); JSONArray jsonArray = new JSONArray(); jsonArray.put(childObject1);
jsonArray.put(childObject2);
requestParams.put("addInfo", jsonArray); request.body(requestParams.toString());
Response response = request.post("https://api-dev.adp.com/api/*/*/*");

发送Json请求2

import com.github.openjson.JSONArray;
import com.github.openjson.JSONObject;
import com.westone.cx.performance.common.AccountConst;
import io.restassured.RestAssured;
import io.restassured.config.SSLConfig;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.hamcrest.Matchers.*;
public class RestAssuredSampler {
public static void main(String[] args) {
RestAssured.useRelaxedHTTPSValidation();
String requestParams = "{\"aaa\":\"11111\",\"bbb\":\"22222\"}";
RequestSpecification request = RestAssured.given()
// .config((RestAssured.config().sslConfig(new SSLConfig().relaxedHTTPSValidation())))
.header("Content-Type", "application/json");
request.body(requestParams);
Response response = request.post("http://url");
response.prettyPrint();
}
}

Json响应

given().
headers(headers).
contentType("application/json").
body(jsonString).
when().
post(url).
then().
log().body().
assertThat().
statusCode(200).
body("$.size()",equalTo(1)).
body("[0].contactMethods.size()",equalTo(2));

Reference

https://github.com/RookieTester/rest-assured-doc/blob/master/2016-12-12-【接口测试】rest-assured用户手册中文版.markdown#JSON(使用JsonPath)

java api

http://static.javadoc.io/io.rest-assured/rest-assured/3.0.1/index.html

RestAssured的更多相关文章

  1. restassured - JsonPath

    https://github.com/rest-assured/rest-assured/blob/master/json-path/src/test/java/io/restassured/path ...

  2. rest-assured : Restful API 测试利器 - 真正的黑盒单元测试(跟Spring-Boot更配哦,更新至spring-boot1.4.1)

    { "Author":"tomcat and jerry", "URL" :"http://www.cnblogs.com/tom ...

  3. 就是这么简单!使用Rest-assured 测试Restful Web Services

    使用 Rest-assured 测试 Restful Web Services 转载注明出处: http://www.cnblogs.com/wade-xu/p/4298819.html 这里向大家介 ...

  4. Rest-Assured

    Rest-Assured完整的测试例子 http://blog.csdn.net/win7system/article/details/52468078 使用 Rest-assured 测试 Rest ...

  5. REST-assured 3发送图片

    上传图片,需要media_id,从上传临时素材获取:https://work.weixin.qq.com/api/doc#10112 https://qyapi.weixin.qq.com/cgi-b ...

  6. REST-assured 2发送消息代码重构

    将获取token的方法封装到公共类 #java package date811; import io.restassured.response.Response; import org.testng. ...

  7. REST-assured 2发送文字到接口

    获取token https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRECT #java package ...

  8. Rest-assured 写日志到 log4j

    背景: 采用Rest-assured,日志采用log4j,发现Rest-assured本身只支持打印日志到控制台,但期望打印到文件中以便排查问题 请求打印的语句只能输出到控制台 given().log ...

  9. Rest-Assured 测试框架

    Rest-Assured 是一个测试 Restful Web Service 的 Java 类库,我们能够测试各种各样的请求组合,依次测试核心业务逻辑的不同组合. 它是通过发送特定的rest api, ...

  10. rest-assured之如何指定请求数据(Specifying Request Data 包括请求参数、请求头、cookie等)

    我们除了可以为一个请求指定请求参数之外,还可以指定请求头(header).cookies.请求体(body)以及请求内容类型(content-type)等,下面我们就来一一介绍一下: 一.请求HTTP ...

随机推荐

  1. Redis+Sentinel安装与配置

    在这里我们搭建的是一个1主3从的redis+3个哨兵集群的环境,由于是在一台物理机上,所有我们用端口区分. 物理机IP:192.168.0.12 主节点master端口:6301 从节点slave1端 ...

  2. Delphi DLL文件的动态调用

    樊伟胜

  3. linux网络协议栈(四)链路层 vlan处理

    转:http://blog.csdn.net/u010246947/article/details/18224517 4.6.VLAN处理: 4.6.1.vlan原理 对于带vlan的以太网报文,其以 ...

  4. Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)

    Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point ( ...

  5. 生成静态libevent

    INCLUDE C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include D:\vs2013\VC\include LIB C:\Prog ...

  6. 单调队列优化&&P1886 滑动窗口题解

    单调队列: 顾名思义,就是队列中元素是单调的(单增或者单减). 在某些问题中能够优化复杂度. 在dp问题中,有一个专题动态规划的单调队列优化,以后会更新(现在还是太菜了不会). 在你看到类似于滑动定长 ...

  7. kubernetes(K8S)快速安装与配置集群搭建图文教程

    kubernetes(K8S)快速安装与配置集群搭建图文教程 作者: admin 分类: K8S 发布时间: 2018-09-16 12:20 Kubernetes是什么? 首先,它是一个全新的基于容 ...

  8. [React] Always useMemo your context value

    Have a similar post about Reac.memo. This blog is the take away from this post. To understand why to ...

  9. C# Lambda Left Join AND Group by Then Sum

    var list = List1.Join( List2, l1 => new { l1.Cityid }, l2 => new { l2.Cityid }, (item1, item2) ...

  10. 4、路由事件 RoutedEvent

    路由事件的类型:具体参考https://www.cnblogs.com/jellochen/p/3475754.html Tunnel隧道方式:路由事件使用隧道策略,以便事件实例通过树向下路由(从根到 ...