• 当面临重复性测试工作的解决思路


    是有这么一个要求,需要用户请求一次接口,会推给他他们一次实验结果,次数太少无法看到自己设置的概率是否符合。内容十分简单,不复杂,但是当任务并行的时候,怎么才能保证质量又保证测试范围和效率,才是首要解决的问题,所以我们并不是需要多么高大上的测试代码,怎么简单怎么来。

    代码很简单,我们在测试过程中首先要保证正确性,其次是提高效率,我在其他项目过程中执行了几次脚本,最后发现比率没问题,测试前还跟开发review了一下脚本和思路,也运行过1000 5000 10000次,比率都是符合要求的。后来,我在和开发沟通过程中还了解到了random的seed的作用,seed不能被单独调用,当seed后面数值一致的时候,才会获取两组相同的随机数。这样可以控制实验变量,这样更能设计实验更准确,更具有实验指导性。

    #coding=utf-8
    import requests
    import json
    import time
    
    
    def testExpClassAB(ii):
        # 定义登录获取cookie
        # post请求方法
        login_url = "https://loginXXXXXXXXXXXXXXXXXXXXX" #登录接口地址
        api_url = "https://VVVVVVVVVVVVV" #被测接口连接
        data_login = {"sign": "XXXXXXX", "pwd": "XXXXX", "vcode": 0}
        login_re = requests.post(login_url, data=data_login)
        login_cookie = login_re.cookies
        data_expclass = {
            "step": 3,          # 步骤 
            "gradeId": 8,       # 年级
            "subjectId": 2,     # 学科 
            "provinceId": 1}    # 省市 
        i = 1
        flag_407 = 0.0
        flag_408 = 0.0
        flag_4 = 0.0
    
        while i <= ii:
            expclass = requests.post(api_url, data=data_expclass, cookies=login_cookie)
            re_content = json.loads(expclass.content)
            print("第"+str(i)+"条:"+str(re_content['data']))
            for item in re_content['data']:
    
               if str(item['timeSlot']).find('[407]') > 0:
                   flag_407 += 1
    
               elif str(item['timeSlot']).find("[408]") > 0:
                   flag_408 += 1
    
               elif str(item['timeSlot']).find("[4]") > 0:
                   flag_4 += 1
               else:
                   pass
            i += 1
            time.sleep(0.5)
        print("flag_4="+str(flag_4), "flag_407="+str(flag_407), "flag_408="+str(flag_408))
        percent_4 = flag_4/(7*i)
        percent_407 = flag_407/(7*i)
        percent_408 = flag_408/(7*i)
        print("percent_4="+str(percent_4), "percent_407="+str(percent_407), "percent_408="+str(percent_408))
    
        percent_sum = percent_4+percent_407+percent_408
        print("percent_sum : "+str(percent_sum))
    
    
    if __name__ == "__main__":
        Numbers = 10
        try:
            testExpClassAB(Numbers)
        except Exception as e:
            print("本次测试异常:"+e)
        print("============测试结束!============")
    

      

  • 相关阅读:
    VMware虚拟机网络设置
    Spring4 In Action-7.1.2-自定义DispatcherServlet配置、添加其他的Servlet和Filter
    Spring4 In Action-5.2.3-Spring Web应用程序-向页面输出列表、接收参数、接收表单
    Spring4 In Action-5.2.2-Spring Web应用程序-简单的控制器实现跳转
    Spring4 In Action-4.3-@AspectJ-args-往切面传递参数
    Spring4 In Action-4.2-@AspectJ-切面
    java.lang.IllegalStateException: Failed to load ApplicationContext
    Spring4 In Action-3.5.1-@PropertySource运行时注入值
    Spring4 In Action-3.2@Scope单例、多例Bean
    Spring In Action-3.2@Conditional条件化Bean
  • 原文地址:https://www.cnblogs.com/yuki-nana/p/11092521.html
Copyright © 2020-2023  润新知