配置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. 正确理解这四个重要且容易混乱的知识点:异步,同步,阻塞,非阻塞,5种IO模型

    本文讨论的背景是Linux环境下的network IO,同步IO和异步IO,阻塞IO和非阻塞IO分别是什么 概念说明 在进行解释之前,首先要说明几个概念: - 用户空间和内核空间 - 进程切换 - 进 ...

  2. IMP-00058: ORACLE error 1882 encountered

    问题现象: IMP: ORACLE error encountered ORA: timezone region not found ORA: at "SYS.DBMS_EXPORT_EXT ...

  3. php 垃圾处理机制

    在php5.3版本之前, php变量的回收机制只是简单的通过计数来处理(当refcount=0时,会回收内存),但这样会出现一个问题 $a=array("str"); $a[]=& ...

  4. PAT乙级1013

    题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805309963354112 题解一 从第一个素数开始找起,输出 ...

  5. 【wqs二分 || 决策单调性】cf321E. Ciel and Gondolas

    把状态看成层,每层决策单调性处理 题目描述 题目大意 众所周知,贞鱼是一种高智商水生动物.不过他们到了陆地上智商会减半.这不?他们遇到了大麻烦!n只贞鱼到陆地上乘车,现在有k辆汽车可以租用.由于贞鱼们 ...

  6. 如何用eclipse进行jar文件打包?

    直接导出runnable jar,如下图所示: 然后选择导出runnable jar: 关于library handling部分的解释如下: (1)Extract required libraries ...

  7. pycharm运行程序,总是出现IPthony界面(IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help. PyDev console: using IPython 6.2.1)

    解决方式如下: 取消即可.

  8. Eclipse快捷方式早知道!Productive Workflow不再是问题

    MyEclipse CI 2019.4.0安装包下载 本文将为大家介绍Eclipse快捷方式列表,希望可以帮助您提供工作效率.快捷方式主要分以下几个区域: 导航 通用编辑 Java编辑器 插件开发 工 ...

  9. k8sStatefulSet控制器

    一.StatefulSet概述 应用程序存在有状态和无状态两种类别,因为无状态类应用的pod资源可按需增加.减少或重构,而不会对由其提供的服务产生除了并发相应能力之外的其他严重影响.pod资源的常用控 ...

  10. Ubuntu 16.04安装docker详细步骤

    1. 卸载之前的旧版本 sudo apt-get remove docker docker-engine docker-ce docker.io 2. 更新apt包 sudo apt-get upda ...