Example tests and snippets

Checking Status Codes

You can configure LoadForge to expect a certain status code or consider the response a failure if it does not receive it. This is useful for checking APIs, verifying certain error cases, and more.

Below is a snippet that allows you to test, for example, that the webserver actually returns a 404 not found.

You can apply this to various use cases such as expecting a specific 4xx or 2xx reply from certain content types. If the response below was not a 404 you would see an error reported in your LoadForge report.


import time
from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
    wait_time = between(3, 5)

    def index_page(self):

        with self.client.get("/does_not_exist/", catch_response=True) as response:
            if response.status_code == 404:

Locust Test Example

LoadForge is powered by locust, meaning open source locust users can copy this script as well. If you are a locust user, consider importing your script to LoadForge to supercharge your testing!

Including static content