“相信一万行代码的理论!
讲完了基类的时间接下来就是模块类。本期分享内容是以我们某个项目的usercenter
模块类内容,包含了用户Users
管理类和自动化测试用例的编写等等。关于自动化用例,我思路是:编写一个可以永远不用维护数据的用例,然后保证测试数据不被污染,基本可以高枕无忧。一般不写死数据,除非是确定不会变的项目静态配置,不搞参数化,不做条件预设,全面监控,及时预警,这样会节省很多维护成本。单接口的参数化测试用例,则采取另外一种自动化方案,放到下期再讲。
欢迎各位多提提意见,关注FunTester
交流测试相关。
gitee地址:https://gitee.com/fanapi/tester
package com.okayqa.studentapd.function;
import com.alibaba.fastjson.JSONObject;
import com.fun.frame.Output;
import com.fun.frame.Save;
import com.fun.utils.Join;
import com.fun.utils.RString;
import com.fun.utils.Time;
import com.fun.utils.WriteRead;
import com.okayqa.common.Common;
import com.okayqa.common.Users;
import com.okayqa.studentapd.base.OkayBase;
import com.okayqa.studentapd.profile.UserApi;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
public class UserCenter extends OkayBase {
private static Logger logger = LoggerFactory.getLogger(UserCenter.class);
public UserCenter(OkayBase okayBase) {
super(okayBase);
}
/**
* 获取用户信息
*
* @return
*/
public JSONObject getUserInfo() {
String api = UserApi.USER_INFO;
JSONObject params = getParams();
JSONObject response = getPostResponse(api, params);
output(response);
return response;
}
/**
* 修改密码,默认会把用户名当做密码,会更新当前用户的token
*
* @return
*/
public JSONObject modifyPwd(String oldpwd, String newpwd) {
String url = UserApi.MODIFY_PWD;
JSONObject params = getParams();
params.put("newpwd", getPassword(newpwd));
params.put("oldpwd", getPassword(oldpwd));
JSONObject response = getPostResponse(url, params);
output(response);
if (isRight(response)) {
String string = response.getJSONObject("data").getString("token");
this.setToken(string);
super.setToken(string);
}
return response;
}
public void testDemo001() {
OkayBase okayBase = new OkayBase(Users.getStuUser(1393), WriteRead.readTextByString("testdemo001"));
UserCenter userCenter = new UserCenter(okayBase);
String stringWithoutNum = RString.getStringWithoutNum(10);
userCenter.modifyPwd(userCenter.pwd, stringWithoutNum);
new OkayBase(Users.getStuUser(1393), stringWithoutNum);
Save.info(stringWithoutNum,"testdemo001");
}
/**
* 更新用户头像
*
* @return
*/
public JSONObject uploadAvatar() {
JSONObject params = getParams();
params.put("avatar", "file");
JSONObject response = getPostResponse(UserApi.UPLOAD_AVATAR, params, new File(Common.PIC_PATH));
output(response);
return response;
}
/**
* 回复列表
*
* @return
*/
public JSONObject feedBackList() {
String api = UserApi.FEED_BACK_LIST;
JSONObject params = getParams();
params.put("currentpage", "1");
JSONObject response = getPostResponse(api, params);
output(response);
return response;
}
/**
* 反馈
*
* @return
*/
public JSONObject feedBack() {
String api = UserApi.FEED_BACK;
JSONObject params = getParams();
params.put("content", "我是测试:" + Time.getDate());
JSONObject response = getPostResponse(api, params);
Output.output(response);
return response;
}
public JSONObject submitSubject(int... subjects) {
String api = UserApi.SUBJECT_SUBMIT;
JSONObject params = getParams();
params.put("schoolTypeId", 1);
params.put("subjectIds", Join.join(ArrayUtils.toObject(subjects), ",", "[", "]"));
params.put("gradeIds", "[12]");
params.put("typeId", 1);
params.put("currentpage", 1);
params.put("contype", 3);
JSONObject response = getPostResponse(api, params);
output(response);
return response;
}
/**
* 小鹅通验证
*
* @return
*/
public JSONObject checkToken() {
String api = UserApi.CHECK_TOKEN;
JSONObject params = getParams();
params.put("source", "imcenter");
params.put("utype", 1);
params.put("user_info", getJson("gender=1", "avatar_url=https://www.google.com", "nickname=FunTester"));
JSONObject response = getPostResponse(api, params);
output(response);
return response;
}
}