Steps to Stress Test Your API Using Locust
1. Install Locust
Install Locust using pip:
bashCopy codepip install locust
2. Write a Locust Test Script
Create a locustfile.py with the following content:
from locust import HttpUser, task, between
class LoginUser(HttpUser):
wait_time = between(1, 2) # Simulates user waiting time between tasks
# Specify the base host for the API
host = "https://api.hwork.ph"
@task
def login(self):
self.client.post("/auth/login", json={
"email": "[email protected]",
"password": "password"
})
-
Replace
/auth/loginwith the endpoint of your API. -
Update the
emailandpasswordvalues to match your test credentials.
3. Run the Locust Test
Start Locust in the terminal:
locust
4. Access Locust UI
Open your browser and go to:
arduinoCopy codehttp://localhost:8089