企业微信-rest-assured接口测试项目实战(一)

2019-03-25  本文已影响0人  DayBreakL

技术准备:

项目准备:

熟悉接口:

使用企业微信提供的接口调试工具:

建立连接:获取AccessToken
请求地址: https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wwad5387da586768d8&corpsecret=MEsk6ytKetMfjkehk8T2GoCTh6Zbmq1KbIYxurO93lQ
返回结果: HTTP/1.1 200 OK
Connection: keep-alive
Error-Code: 0
Error-Msg: ok
Content-Type: application/json; charset=UTF-8
Content-Length: 277

 {"errcode":0,"errmsg":"ok","access_token":"OaGWL0unV5KM2AecoGs-gs8rZaLM3GAp1O2jiAZJ_rd0FxBM_7hH0SEbX7dN9IyT1WNEe7lDRK9kufYR7atay2FML4mbn3CUUC7hZG2irpLvcJ-SGEfdbcc0VpdGQwAqso9yePnAUBkRAbmRaCI7A1dQ-UtutluJzbwMIJKdIysID2FJxYJYJilCUXGSR0axP8lw-6euCp1CjCekhuJiVg","expires_in":7200}

access_token就是我们需要的
"expires_in":7200表示access_token的失效时间,7200秒,2小时
发送消息接口示例


body填入的内容:
{
   "touser" : "@all",
   "toparty" : "",
   "totag" : "",
   "msgtype" : "text",
   "agentid" : 1000002,
   "text" : {
       "content" : "Daybreak提醒您,您的快递已到,请携带工卡前往邮件中心领取。\n出发前可查看<a href=\"http://work.weixin.qq.com\">邮件中心视频实况</a>,聪明避开排队。"
   },
   "safe":0
}

待测业务

注意事项

接口测试用例实现

import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import static org.hamcrest.core.IsEqual.equalTo;

public class TestGetToken {
    @Test
    public void testToken(){
        RestAssured.given().log().all()
                //入参
                .queryParam("corpid","wwad5387da586768d8")
                .queryParam("corpSecret","MEsk6ytKetMfjkehk8T2GoCTh6Zbmq1KbIYxurO93lQ")
            //when表示触发条件
            .when().get("https://qyapi.weixin.qq.com/cgi-bin/gettoken")
            //then对结果断言
            .then().log().all().statusCode(200).body("errcode",equalTo(0));
    }
}

这是最基础的用例实现。但是每一条用例都这么写,会有大量重复的代码,所以要对代码进行封装,提高代码的复用性。

上一篇 下一篇

猜你喜欢

热点阅读