FunTester 模块类和自动化用例实践--视频演示

FunTester · 2020年04月09日 · 724 次阅读

相信一万行代码的理论!

讲完了基类的时间接下来就是模块类。本期分享内容是以我们某个项目的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;
    }

}


  • 郑重声明:公众号 “FunTester” 首发,欢迎关注交流,禁止第三方转载。

技术类文章精选

无代码文章精选

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册