In the previous lesson, we learned about the different ways to inject users into the simulation. In this lesson, we will learn how to validate the metrics of the responses.

What are assertions?

Assertions are used to verify the global statistics like the total number of successful requests, the total number of failing requests, total response mean time, maximum of total response times, minimum of total response times, etc.

Defining scope

Gatling allows us to define the scope and apply assertions to that scope. For example, it can be applied to:

  • global – uses the statistics calculated for all the requests that were hit during the entire simulation.
  • forAll – uses the statistics calculated for an individual request.
  • details(path) – uses the statistics calculated for requests having the given path.

Statistics

We can call any of the following statistics on the above scopes:

  • responseTime – fetches the response time in milliseconds.
  • allRequests – fetches all the requests.
  • failedRequests – fetches all the failed requests.
  • successfulRequests – fetches all the succeeded requests.
  • requestsPerSec – fetches the rate at which the requests were sent.

Metrics

Below are the metrics that are applicable to the requests and response times:

Applicable to response times

  • min – performs the assertion on the minimum of the metric.

  • max – performs the assertion on the maximum of the metric.

  • mean – performs the assertion on the mean of the metric.

  • stdDev – performs the assertion on the standard deviation of the metric.

  • percentile1 – performs the assertion on the first percentile of the metric, as configured in gatling-defaults.conf (default is 50th).

  • percentile2 – performs the assertion on the second percentile of the metric, as configured in gatling-defaults.conf (default is 75th).

  • percentile3 – performs the assertion on the third percentile of the metric, as configured in gatling-defaults.conf (default is 95th).

  • percentile4 – performs the assertion on the fourth percentile of the metric, as configured in gatling-defaults.conf (default is 99th).

  • percentile(value: Double) – performs the assertion on the given percentile of the metric. The given parameter is a percentage, between 0 and 100.

Applicable to number of requests (all, failed or successful)

  • percent – uses the value as a percentage between 0 and 100.

  • count – performs the assertion directly on the count or the total number of requests.

Conditions

  • lt(threshold) – checks whether the metric value is less than the given threshold.

  • lte(threshold) – checks whether the metric value is less than or equal to the given threshold.

  • gt(threshold) – checks whether the metric value is greater than the given threshold.

  • gte(threshold) – checks whether the metric value is greater than or equal to the given threshold.

  • between(thresholdMin, thresholdMax) – checks whether the metric value is between two given thresholds, including both the bounds.

  • between(thresholdMin, thresholdMax, inclusive = false) – checks whether the metric value is between two given thresholds excluding the bound values.

  • is(value) – checks whether the metric value is equal to the given value.

  • in(sequence) – checks whether the metric value is in the given sequence.

These above conditions can be chained several times on the same metric to validate different aspects of the metric.

Examples

Assert that the max response time of all requests is less than 1000 ms.

setUp(scenario).assertions(global.responseTime.max.lt(1000))

Get hands-on with 1400+ tech skills courses.