接口测试业务验证--视频演示
Posted FunTester
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了接口测试业务验证--视频演示相关的知识,希望对你有一定的参考价值。
接口框架的基础功能已经讲完了,接下来会分享一些接口测试实践。今天分享了接口一般的业务验证,注册用户和用户登录。借助开源社区提供的接口来做演示。写了一些测试脚本,针对独立性较高的接口测试项目如何快速验证。没有使用所谓数据驱动,也没有采用断言(使用预警代替),总的来讲,更像BDD一些。中间也用到了多接口相互验证的功能。
★相信一万行代码的理论!
”
视频专题:
接口测试中业务验证
代码
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”,欢迎关注交流,禁止第三方(腾讯云除外)转载、发表。
技术类文章精选
无代码文章精选
以上是关于接口测试业务验证--视频演示的主要内容,如果未能解决你的问题,请参考以下文章
Express实战 - 应用案例- realworld-API - 路由设计 - mongoose - 数据验证 - 密码加密 - 登录接口 - 身份认证 - token - 增删改查API(代码片段