locust 测试用例

from locust import TaskSet, task, User,HttpUser
import subprocess
import scmlogin as lg
# from locust import events  事件
#
# @events.test_start.add_listener
# def on_test_start(**kw):
#     print("test is starting")
#
# @events.test_stop.add_listener
# def on_test_start(**kw):
#     print("test is stopping")

class MyTasks(TaskSet):
    """
    创建测试任务类,需要继承TaskSet
    可以添加多个测试任务
    """
    # 每个测试任务,往往会以实例方法的形式来呈现
    # 同时需要使用task装饰器来装饰测试任务
    @task
    def one_task(self):
        param = {'no': 1, 'sku': 'qd', 'startSn': 1, 'endSn': 1000, "prefix": "66666"}
        reponse=self.client.post(url="",data=param,cookies=lg.cookie)
        print(reponse.status_code)
        # print(reponse.json())
        # print("测试任务1")

    @task
    def two_task(self):
        param2={'sku': 'nk', 'rfids': '000000000000476898000307,201607000000000000010827,201607000000000000010797','isReplace': 'true'}
        reponse=self.client.post(url="",data=param2,cookies=lg.cookie)
        print(reponse.status_code)

    @task
    def three_task(self):
        param3={'sku': 'qd2', 'prefix': 'qd2', 'startSn': 1, 'endSn': 8}
        reponse=self.client.post(url="",data=param3,cookies=lg.cookie)
        print(reponse.status_code)
    @task
    def four_task(self):
        param4={'no': 3, 'skuRfidJson': '[{"sku": "nk","rfids":["0005399001480039","0005399001480040","0005392001540005"]},{"sku": "qd","rfids":["0005392001540006","0005392001540007"]}]'}
        reponse=self.client.post(url="",data=param4,cookies=lg.cookie)
        print(reponse.status_code)
    @task
    def five_task(self):
        param5={'no': 4, 'sku': 'qd', 'uniqueCodeJsonStr': "[{uniqueCode:'00js22',sdys:1}]"}
        reponse=self.client.post(url="",data=param5,cookies=lg.cookie)
        print(reponse.status_code)

# class RunTasks(User):
#     """
#     创建运行测试类,需要继承Locust父类
#     """
#     tasks = [MyTasks]   # 指定测试任务类,使用task_set覆盖父类的类属性
#     min_wait = 2000      # 指定启动任务间隔的时间范围(单位毫秒):2~5秒之间
#     max_wait = 5000

class MobileUserLocust(HttpUser):
    u"""
    min_wait :用户执行任务之间等待时间的下界,单位:毫秒。
    max_wait :用户执行任务之间等待时间的上界,单位:毫秒。
    """
    # weight = 3
    tasks = [MyTasks]
    host = "http://localhost:8888"  #(待测试的ip或者域名)
    min_wait = 2000
    max_wait = 5000
if __name__ == "__main__":
    subprocess.Popen("locust -f locustfile2.py", shell=True)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值