The assertion is an API. Assertions are uses to verify that some global statistics like the number of failed requests is matching the exceptions for a complete simulation. Assertions are registered for a simulation using the method named: assertion in the setUp.
Following is an example of using the assertion function:
setUp(scn).assertions(
global.responseTime.max.lt(50),
global.successfulRequests.percent.gt(95)
)
It may be noted that this method may take many assertions that we like. The assertion API provides a dedicated DSL for chaining some steps. They are summarized below:
An assertion is able to test statistics calculated from all requests or some time from a part of it. Below, we have seen that how differently may the scope of the assertion can be defined.
Let us see the below example of performing an assertion on the request Index in the group Search. This can be done by:
details("Search" / "Index")
There are different parameters that we call our metrics and are relevant to response time only.
gatling.conf. However, the default is the 50th.gatling.conf. It should be mentioned that the default is 75th. Similar is the case for the percentile3 and the percentile4 which in default percentile number is the 95th and 99th respectively.
The use of Conditions is that many different conditions can be applied to the same metric, making it more reliable to use a metric differently.
Let us see the different ways of how we can condition the metric using some keywords or better said as functions. Some are listed below:
Let us see how we can use assertions, below is a listed example of using assertions:
// Assert that the max response time of all requests is less than 100 ms
setUp(scn).assertions(global.responseTime.max.lt(100))
// Assert that every request has no more than 5% of failing requests
setUp(scn).assertions(forAll.failedRequests.percent.lte(5))
// Assert that the percentage of failed requests named "Index" in the group "Search"
// is exactly 0 %
setUp(scn).assertions(details("Search" / "Index").failedRequests.percent.is(0))
// Assert that the rate of requests per seconds for the group "Search"
setUp(scn).assertions(details("Search").requestsPerSec.between(100, 1000))
Gatling generates two reports in the js directory, if the simulations define assertions, they are: One is a JSON file and the other is the JUnit file.
global.responseTime.max.lt(50) , forAll.failedRequests.count.lt(5) and details("Search Request").successfulRequests.percent.gt(90)
Go to the js directory which is inside the directory result of Gatling's directory. Inside the js directory, we have our JSON file created. We may open it now, with the help of an editor, and see the result.
The latter can be used with Jenkins's JUnit Plugin. Below is an example:
[
{
"path": "Global",
"target": "max of response time",
"condition": "is less than",
"expectedValues": [50],
"result": false,
"message": "Global: max of response time is less than 50",
"actualValue": [145]
},
{
"path": "requestName",
"target": "percent of successful requests",
"condition": "is greater than",
"expectedValues": [95],
"result": true,
"message": "requestName: percent of successful requests is greater than 95",
"actualValue": [100]
}
]