近期在做稳定性测试,jemeter应用起來不稳定 ,而耗费电脑内存很大,loadrunner是收费的,虽然有破译 ,但不太社会道德!之后应用了开源的locust locust是根据协程的开源的工作压力功能测试架构,在网上因为我找了很多的材料配备及示例,但全是根据旧版的 ,在最新版本一直出错,之后根据搜索官网的示例,终于知道缘故——是由于locust升級以后 ,一些主要参数及自变量发生了转变(实际怎样从官网表明文本文档如何科学研究文中不作过多阐释) 绝大多数网址上都是有以下编码:

近期在做稳定性测试 ,jemeter应用起來不稳定,而耗费电脑内存很大,loadrunner是收费的 ,虽然有破译,但不太社会道德!之后应用了开源的locust

locust是根据协程的开源的工作压力功能测试架构,在网上因为我找了很多的材料配备及示例 ,但全是根据旧版的,在最新版本一直出错,之后根据搜索官网的示例 ,终于知道缘故——是由于locust升級以后,一些主要参数及自变量发生了转变(实际怎样从官网表明文本文档如何科学研究文中不作过多阐释)

绝大多数网址上都是有以下编码:

class WebsiteUser(HttpLocust):
    task_set = UserBehavior #启用自定方式 UserBehavior
    min_wait = 3000 #最少等待的时间
    max_wait = 6000 #较大 等待的时间

如今改为了:

class UserBehavior(HttpUser): #
    wait_time = between(5, 15) #立即把等待的时间范畴应用wait_time写在了自定方式UserBehavior里

且启用的情况下在python文档以后再加上自定方式的主要参数UserBehavior 就可以

os.system("locust -f load_test.py UserBehavior --host=http://xxxx.xxxx.xxxx.xxxx:8090/YLAPI")

下列为详细编码:

from locust import User, task, between, HttpUser

class UserBehavior(HttpUser):
    wait_time = between(5, 15)
    @task(1) #Post要求
    def firstTest(self):

        header = {"Content-Type": "application/json"}
        payload = {
            "versionNum": "10",
            "platform": "android"
        }

        req = self.client.post("/Api/app/version/appCheck", data=payload, headers=header, verify=False)
        if req.status_code == 200:
            print("success")
        else:
            print("fails:"   str(req.status_code))

    # @task(1) #get请求
    # def about(self):
    #     self.client.get("/about/")



if __name__ == "__main__":
    import os
    #os.system("locust -f load_test.py UserBehavior")
    os.system("locust -f load_test.py UserBehavior --host=http://xxxx.xxxx.xxxx.22:8090/YLAPI")

  Enjoy your latest version locust script code on your hand :-)

 reference: 

1) https://www.cnblogs.com/lxmtx/p/12580031.html

 

文章来源于网络,如有侵权请联系站长QQ61910465删除
本文版权归qu快排seo www.sEoguRuBlog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ√61910465