1. Thinking
1. What is performance automated 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?
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
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:
2. Basic usage
Create a locustfile.py file in the project root directory
◆ Perform performance test
After running, the console will listen to a port locally
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
3. Comprehensive case exercise
1. Write automated test scripts
◆ Create test_load.py file in the project root directory
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
3. Open the web ui interface for configuration
Set the number of concurrent users to 10, and create a user every 5 seconds
Screenshot of pressure test process
Beautiful stress test report
Stress test failure details
Download pressure test statistics
Downloaded csv file of stress test statistics
Four, summary
◆ 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