The village chief tells you: Python is so easy to implement automated performance testing

1. Thinking

1. What is performance automated testing?

The village chief tells you: Python is so easy to implement automated performance testing

 

◆  Performance

△ System load capacity

△ Stability under overload operation

△ System bottleneck

◆  Automated testing

△ Use program instead of manual

△ Improve test efficiency

◆  Performance automation

△ Use code to simulate a large number of users

△ Let users make concurrent requests

△ Multi-page and multi-user concurrent requests

△ Collecting parameters and statistic system load capacity

△ Generate report

2. What is the performance automation test library in Python?

The village chief tells you: Python is so easy to implement automated performance testing

 

locust library

◆  Use Python

△ Use code to create batch users

◆  Distributed

△ Distributed performance test can be performed on multiple servers

△ Strong scalability

◆  Stable and widely used

△ Can stand the test in various scenarios

△ Show test details based on web ui interface

△ Can measure any system

2. Basic operation

The village chief tells you: Python is so easy to implement automated performance testing

 

1. Install locust

◆  Use the official pypi source to install

pip install locustio

◆  Use Douban pypi source to install (recommended)

pip install -i https://pypi.douban.com/simple locustio

After the installation is successful, a new command will be added to the cmd console, you can enter the following command to view:

The village chief tells you: Python is so easy to implement automated performance testing

 

2. Basic usage

Create a locustfile.py file in the project root directory

The village chief tells you: Python is so easy to implement automated performance testing

 

The village chief tells you: Python is so easy to implement automated performance testing

 

◆  Perform performance test

The village chief tells you: Python is so easy to implement automated performance testing

 

After running, the console will listen to a port locally

The village chief tells you: Python is so easy to implement automated performance testing

 

a. The program file must be named locustfile.py

b. If it is named one_example.py, you need to run it like this

locust -f one_example.py

◆  Open the UI setting interface in the browser

△ Open with localhost:8089 by default

The village chief tells you: Python is so easy to implement automated performance testing

 

The village chief tells you: Python is so easy to implement automated performance testing

 

3. Comprehensive case exercise

The village chief tells you: Python is so easy to implement automated performance testing

 

1. Write automated test scripts

◆ Create test_load.py file in the project root directory

The village chief tells you: Python is so easy to implement automated performance testing

 

The village chief tells you: Python is so easy to implement automated performance testing

 

The village chief tells you: Python is so easy to implement automated performance testing

 

The village chief tells you: Python is so easy to implement automated performance testing

 

2. Use the command line to run

◆ Open the Pycharm Terminal console and run the following command:

Note: The --host parameter specifies the http host address, and the -f parameter specifies the file name of the pressure test program

 

The village chief tells you: Python is so easy to implement automated performance testing

 

3. Open the web ui interface for configuration

Set the number of concurrent users to 10, and create a user every 5 seconds

The village chief tells you: Python is so easy to implement automated performance testing

 

Screenshot of pressure test process

The village chief tells you: Python is so easy to implement automated performance testing

 

Beautiful stress test report

The village chief tells you: Python is so easy to implement automated performance testing

 

Stress test failure details

The village chief tells you: Python is so easy to implement automated performance testing

 

Download pressure test statistics

The village chief tells you: Python is so easy to implement automated performance testing

 

Downloaded csv file of stress test statistics

The village chief tells you: Python is so easy to implement automated performance testing

 

Four, summary

The village chief tells you: Python is so easy to implement automated performance testing

 

◆ locust is extremely powerful for pressure measurement

◆ Support distributed deployment

◆ Simple interface provided

◆ Pressure test code is very easy to write

◆ Provide UI interface to configure

◆ Beautiful and detailed chart statistics

Recommend a software testing learning exchange group: 785128166, there are shared videos, interview guidance, test materials, mind maps, and videos in the group. They are all dry goods, you can download and watch. Mainly share test foundation, interface test, performance test, automated test, TestOps architecture, Jmeter, LoadRunner, Fiddler, MySql, Linux, resume optimization, interview skills, and actual video data of large-scale test projects. Use every minute and every second of your time to learn to improve yourself, and don't use "no time" to conceal your mental laziness! Try hard while you are young, and give your future self an explanation!

Public number: Programmer Erhei, after paying attention, you can receive a large amount of learning materials for free.

Good things should be shared with friends
 

Guess you like

Origin blog.csdn.net/m0_52668874/article/details/114850113