性能测试——压测工具locust——安装测试

官网:www.locust.io/

 

 

产品文档:docs.locust.io/en/2.4.1/

 

 

 

安装

  1. 配置好pthon、pycharm
  2. cmd窗口执行:pip3 install locust
  3. 验证:locust -V

 

 

 

 

 

 

 

 

 

 

 

编写python性能接口自动化测试脚本

 

learn_demo03.py

 

import json
from json import JSONDecodeError
from locust import task, HttpUser, between


class UserBehavior1(HttpUser):

    wait_time = between(2, 5)  # 每个用户执行后等待2-5秒

    @task  # Locust 创建一个 greenlet(微线程),一个微线程可以跑很多协程
    def test_login(self):

        response = self.client.get("http://localhost:8080/hello")
        assert response.status_code == 200

 

 

 

 

 

 

执行:  locust -f learn_demo03.py

 

 

 

 

 

 

 

 

结果:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

参考:https://blog.csdn.net/m0_70618214/article/details/131307986

 

posted @ 2024-04-22 10:23  小白龙白龙马  阅读(5)  评论(0编辑  收藏  举报