讲完 get,轮到 post 请求了,本期分享了 post 请求的实现,分享了一些参数依赖的情况。录制过程中翻车了好几次,各位见谅。
视频专题:
今天主要讲了 post 接口的相关测试,前半段主题内容跟上期一致,演示了 post 请求的 Demo,中间翻车好几次,幸亏接口文档比较简单。要是遇到复杂逻辑业务,一次性上车几乎是不可能的。
后半段分享了一个接口测试如何处理校验值,参数依赖等等,只是个简单的 Demo,适合短期测试项目,写完就用,用完就扔的模式,用来做练习很不错。之前做过一些活动和游戏的测试,每周上线一个游戏活动,然后下线,软件工期非常短,这种就比较适合今天讲的模式。对于一个长期项目如何做接口测试以及如何接口自动化,后会有期了。
gitee 地址:https://gitee.com/fanapi/tester
package com.fun;
import com.alibaba.fastjson.JSONObject;
import com.fun.frame.httpclient.FanLibrary;
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) {
// developerLogin();
registerUser();
testOver();
}
public static void registerUser() {
if (StringUtils.isEmpty(APIKEY)) developerLogin();
String url = "https://api.apiopen.top/registerUser";
JSONObject param = new JSONObject();
param.put("apikey", APIKEY);
param.put("name", "FunTester0021");
param.put("passwd", "123456");
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", "这是测试用户!");
HttpPost httpPost = getHttpPost(url, param);
JSONObject response = getHttpResponse(httpPost);
output(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 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);
JSONObject response = getHttpResponse(httpPost);
output(response);
if (response.getIntValue("code") == 200) {
APIKEY = response.getJSONObject("result").getString("apikey");
} else {
fail();
}
}
}