亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python接口測(cè)試對(duì)修改密碼接口進(jìn)行壓測(cè)

 更新時(shí)間:2022年07月21日 14:36:21   作者:FunTester  
這篇文章主要為大家介紹了python接口測(cè)試對(duì)修改密碼接口進(jìn)行壓測(cè)的腳本實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

引言

做接口測(cè)試中,對(duì)于一般性的單業(yè)務(wù)接口測(cè)試很多工具可供選擇,但是對(duì)于一些相關(guān)業(yè)務(wù)相關(guān)性的關(guān)聯(lián)接口測(cè)試就比較麻煩,使用工具比如jmeter、postman、soapui等等就比較麻煩。

我比較偏重腳本化執(zhí)行測(cè)試用例,所以選擇了groovy作為主要語(yǔ)言來(lái)進(jìn)行接口測(cè)試,但是腳本依賴的庫(kù)還是基于之前所在的java為主的測(cè)試框架,有興趣的可以翻翻以前的文章。

項(xiàng)目的架構(gòu)思路是以模塊為基礎(chǔ)把接口分類,然后對(duì)于接口的請(qǐng)求單獨(dú)進(jìn)行實(shí)現(xiàn)。通過(guò)一個(gè)user作為一個(gè)用戶,攜帶各種屬性,如:uname,pwd,token,userinfobean等信息。來(lái)作為各個(gè)模塊類之間的信息傳遞。

回到修改密碼接口,簡(jiǎn)單說(shuō)一下我們接口的邏輯,先登錄,獲取token作為用戶身份的唯一校驗(yàn)值,修改密碼接口參數(shù),newpwd,oldpwd,token。成功之后會(huì)返回新的token,作為用戶繼續(xù)其他操作的校驗(yàn)值。

測(cè)試腳本代碼

分享一下自己的測(cè)試腳本代碼:

class T8 extends OkayBase {
    public static void main(String[] args) {
        int thread =changeStringToInt(args[0])
        int times =changeStringToInt(args[1])
        List<ThreadBase> threads = new ArrayList<>()
        for (int i = 0; i < thread; i++) {
            OkayBase base = getBase(i)
            UserCenter userCenter = new UserCenter(base)
            userCenter.modifyPwd()
            ThreadBase threadBase = new ThreadBase() {
                @Override
                protected void before() {
                }
                @Override
                protected void doing() throws Exception {
                    userCenter.modifyPwd()
                }
                @Override
                protected void after() {
                }
            }
            threadBase.setTimes(times)
            threads.add(threadBase)
        }
        new Concurrent(threads).start()
        allOver()
    }
}

usercenter主要代碼

main方法留了兩個(gè)參數(shù)表示線程數(shù)和單線程請(qǐng)求數(shù),下面是usercenter的主要代碼。

public class UserCenter extends OkayBase {
    private static Logger logger = LoggerFactory.getLogger(UserCenter.class);
    public UserCenter(OkayBase okayBase) {
        super(okayBase);
    }
    public JSONObject modifyPwd() {
        String url = UserApi.MODIFY_PWD;
        JSONObject params = getParams();
        params.put("newpwd", getPassword(this.getUname()));
        params.put("oldpwd", getPassword(this.getPwd()));
        JSONObject response = getPostResponse(url, params);
        output(response);
        if (isRight(response)) {
            String string = response.getJSONObject("data").getString("token");
            this.setToken(string);
        }
        return response;
    }
}

okaybase主要代碼

public class OkayBase extends SourceCode implements IBase {
    private static Logger logger = LoggerFactory.getLogger(OkayBase.class);
    int uid;
    String token;
    String uname;
    String pwd;
    public OkayBase(String uname, String pwd) {
        this.uname = uname;
        this.pwd = pwd;
        login();
    }
    public String getPassword() {
        String s = uname.substring(uname.length() - 6);
        return getPassword(s);
    }
    public String getPassword(String pwd) {
        return RSAUtils.getPassword(pwd);
    }
    public JSONObject getParams() {
        JSONObject json = getJson("uid=" + uid, "token=" + token);
        json.put("imei", "isFake");
        json.put("serial", "W170500652");
        json.put("ua", "f_an_4..0");
        return json;
    }
    public String getPwd() {
        return pwd;
    }
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
    public int getUid() {
        return uid;
    }
    public String getToken() {
        return token;
    }
    public void setToken(String token) {
        this.token = token;
    }
    public String getUname() {
        return uname;
    }
    @Override
    public boolean isRight(JSONObject jsonObject) {
        int code = TEST_ERROR_CODE;
        try {
            code = jsonObject.getJSONObject("meta").getInt("ecode");
            JSONObject data = jsonObject.getJSONObject("data");
            return code == 0 && !data.isEmpty();
        } catch (Exception e) {
            return false;
        }
    }
    /**
     * 測(cè)試結(jié)束,資源釋放
     */
    public static void allOver() {
        FanLibrary.testOver();
    }
}

以上就是python接口測(cè)試對(duì)修改密碼接口進(jìn)行壓測(cè)的詳細(xì)內(nèi)容,更多關(guān)于python修改密碼接口壓測(cè)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論