娃哈哈哈哈哈 发表于 2019-5-23 14:06:12

没明白为什么for循环中的10次已经执行完了,后面还会又开始执行,导致后面注册失败呢


http://www.atstudy.com/files/course/2019/05-15/215118613e71363707.png

from locust import HttpLocust,task,TaskSetclass userBehavior(TaskSet):    #指定测试任务    @task    def test_login(self):      # 定义注册的测试数据      for i in range(10,21):            user = "test" + str(i)            registerData = {"email":user + "@qq.com",                         "username":user,                         "password":"123456",                         "repassword":"123456",                         "captcha":"11111"}            # 发送注册页请求给服务器 post            response = self.client.post("/index.php?controller=simple&action=reg_act",data = registerData)            loc = response.find("恭喜")            if loc >= 0 :                print("测试成功")            else:                print("测试失败")class WebSiteUser(HttpLocust):    host = "http://localhost:8083/iwebshop"    task_set = userBehavior    min_wait = 2000    max_wait = 5000




在学课程
Python测试开发全栈核心课程 互联网测试工程师必修课
http://www.atstudy.com/course/1287

学掌门网校 发表于 2019-5-23 14:29:13

locust关联脚本的循环并不是单纯脚本本身的循环

1、你可以试着去掉循环,locust中设置10个虚拟用户,他就会不断的调用脚本,直到你把locust服务停止

2、所以如果要进行注册的性能测试,不能只是准备10组数据,你想并发多少个用户,就得准备多少个数据,这10个数据只能满足10个用户各执行一次

娃哈哈哈哈哈 发表于 2019-5-23 14:49:58

所以这样的话,工作中如果要测注册功能的话还得一直盯着吗? 因为它执行完所有的数据在执行得时候就报错了 会导致测试结果不准确吧?

还有个问题老师,locust没有地方设置定时执行性能测试任务的功能是吧,你有没有好的办法呢

学掌门网校 发表于 2019-5-23 15:02:46

1. 关于locust的定时开始和停止,你可以看看https://blog.csdn.net/qq_33339479/article/details/87913788

def spawn_run_time_limit_greenlet():
      logger.info("Run time limit set to %s seconds" % options.run_time)
      def timelimit_stop():
            logger.info("Time limit reached. Stopping Locust.")
            runners.locust_runner.quit()
      gevent.spawn_later(options.run_time, timelimit_stop)

里面有详细的说明呵

2. 任何脚本的测试结果,都可以写入测试报告,只要把测试报告设计的足够详细,不需要人盯着,执行后看测试报告就可以了。课程中有关于测试报告的内容呵!
页: [1]
查看完整版本: 没明白为什么for循环中的10次已经执行完了,后面还会又开始执行,导致后面注册失败呢