wfw001-2018

首先我们需要准备好python环境

接口 安装python 插件 locust,网上有很多文章而且都很错,这里不再赘述

我是通过pycharm 编写的代码  导入 HttpLocust,TaskSet,task

 

 from locust import HttpLocust,TaskSet,task

 #新建一个类并继承TaskSet
class TestIndex(TaskSet):
def test_start(self):
pass

@task #配置执行的权重 @task(X)
def test_init(self):
self.client.post("接口的路径", data=接口参数)

#新建一个类继承HttpLocust
class WebSite(HttpLocust):
#实例化TestIndex类
    task_set = TestIndex
#这里可以配置主机域名
host="http://host:port"
#最小时间
min_wait = 1000
#最大时间
max_wait = 3000

代码完成,是不是很简单,接下来 我们通过命令执行,这里以windows为例 首先通过命令提示符进入到xx.py的目录 在执行命令 locust -f xx.py ,如图

 

 

然后通过浏览器访问 http://localhost:8089/ 设置并发数运行结果

 

 

 

分类:

技术点:

相关文章:

  • 2021-12-20
  • 2021-08-16
  • 2019-01-09
  • 2021-09-03
  • 2021-09-03
  • 2021-08-16
  • 2021-01-22
  • 2021-09-03
猜你喜欢
  • 2021-09-19
  • 2021-11-17
  • 2021-09-03
  • 2020-07-30
  • 2021-09-19
  • 2021-09-03
  • 2021-09-03
相关资源
相似解决方案