前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >接口测试业务验证--视频演示

接口测试业务验证--视频演示

作者头像
FunTester
发布2020-04-03 15:24:34
4500
发布2020-04-03 15:24:34
举报
文章被收录于专栏:FunTesterFunTester

接口框架的基础功能已经讲完了,接下来会分享一些接口测试实践。今天分享了接口一般的业务验证,注册用户和用户登录。借助开源社区提供的接口来做演示。写了一些测试脚本,针对独立性较高的接口测试项目如何快速验证。没有使用所谓数据驱动,也没有采用断言(使用预警代替),总的来讲,更像BDD一些。中间也用到了多接口相互验证的功能。

★相信一万行代码的理论! ”

接口测试中业务验证


gitee地址:https://gitee.com/fanapi/tester

代码

代码语言:javascript
复制
package com.fun;


import com.alibaba.fastjson.JSONObject;
import com.fun.config.HttpClientConstant;
import com.fun.frame.httpclient.FanLibrary;
import com.fun.utils.RString;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpPost;

public class AR extends FanLibrary {

    public static String APIKEY;

    public static void main(String[] args) {
        testDemo001();
        testDemo002();

        testOver();
    }

    public static void testDemo001() {
        JSONObject funTester = registerUser("FunTester", RString.getString(10), RString.getString(10));
        int code = funTester.getIntValue("code");
        if (code != 400) fail();
    }

    public static void testDemo002() {
        String name = "Fun" + getMark();
        String pwd = RString.getString(10);
        String remark = RString.getString(10);
        JSONObject funTester = registerUser(name, pwd, remark);
        int code = funTester.getIntValue("code");
        if (code != 200) fail();
        JSONObject result = funTester.getJSONObject("result");
        String name1 = result.getString("name");
        if (!name.equals(name1)) fail();
        String remark1 = result.getString("remarks");
        if (!remark.equals(remark1)) fail();
        userLogin(name, pwd);
    }


    public static JSONObject registerUser(String name, String passwd, String remark) {
        if (StringUtils.isEmpty(APIKEY)) developerLogin();
        String url = "https://api.apiopen.top/registerUser";
        JSONObject param = new JSONObject();
        param.put("apikey", APIKEY);
        param.put("name", name);
        param.put("passwd", passwd);
        param.put("nikeName", "FunTester");
        param.put("headerImg", "http://pic.automancloud.com/sick-jvm-heap-1.png");
        param.put("phone", "13100001111");
        param.put("email", "Fhaohaizi@163.com");
        param.put("vipGrade", "3");
        param.put("autograph", "abc");
        param.put("remarks", remark);
        HttpPost httpPost = getHttpPost(url, param);
        JSONObject response = getHttpResponse(httpPost);
        output(response);
        return response;
    }

    public static void register() {
        String url = "https://api.apiopen.top/developerRegister";
        JSONObject param = new JSONObject();
        param.put("name", "FunTester");
        param.put("passwd", "FunTester");
        param.put("email", "Fhaohaizi@163.com");
        HttpPost httpPost = getHttpPost(url, param);
        JSONObject response = getHttpResponse(httpPost);
        output(response);
    }

    public static void userLogin(String name, String pwd) {
        if (StringUtils.isEmpty(APIKEY)) developerLogin();
        String url = "https://api.apiopen.top/loginUser";
        JSONObject param = new JSONObject();
        param.put("name", name);
        param.put("passwd", pwd);
        param.put("apikey", APIKEY);
        HttpPost httpPost = getHttpPost(url, param);
        JSONObject response = getHttpResponse(httpPost);
        output(response);
        if (!(response.getIntValue("code") == 200)) fail();
    }

    public static void developerLogin() {
        String url = "https://api.apiopen.top/developerLogin";
        JSONObject params = new JSONObject();
        params.put("name", "funtester");
        params.put("passwd", "funtester");
        HttpPost httpPost = getHttpPost(url, params);
        httpPost.addHeader(HttpClientConstant.X_Requested_KWith);
        httpPost.addHeader(getHeader("name", "FunTester"));
        JSONObject response = getHttpResponse(httpPost);
        output(response);
        if (response.getIntValue("code") == 200) {
            APIKEY = response.getJSONObject("result").getString("apikey");
        } else {
            fail();
        }
    }


}


  • 郑重声明:文章首发于公众号“FunTester”,欢迎关注交流,禁止第三方(腾讯云除外)转载、发表。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-03-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 FunTester 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 接口测试中业务验证
  • 代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档