Saturday, August 22, 2020

Jmeter Assertions - Size and Duration Assertion

This is the third posts related to Jmeter Assertions  in my blog. If you wish to read the previous posts, click here.

3. Size Assertion

Size Assertion is used to to check the size of downloaded files. To add size assertion in the test plan, refer the below snapshot (Right click on Sampler -> Add -> Assertions -> Size Assertion).

Let us see an example how to use Size Assertion. I am going to hit the URL "https://reqres.in/api/users?page=2" which gives the below response.

{"page":2,"per_page":6,"total":12,"total_pages":2,"data":[{"id":7,"email":"michael.lawson@reqres.in","first_name":"Michael","last_name":"Lawson","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/follettkyle/128.jpg"},{"id":8,"email":"lindsay.ferguson@reqres.in","first_name":"Lindsay","last_name":"Ferguson","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/araa3185/128.jpg"},{"id":9,"email":"tobias.funke@reqres.in","first_name":"Tobias","last_name":"Funke","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/vivekprvr/128.jpg"},{"id":10,"email":"byron.fields@reqres.in","first_name":"Byron","last_name":"Fields","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/russoedu/128.jpg"},{"id":11,"email":"george.edwards@reqres.in","first_name":"George","last_name":"Edwards","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/mrmoiree/128.jpg"},{"id":12,"email":"rachel.howell@reqres.in","first_name":"Rachel","last_name":"Howell","avatar":"https://s3.amazonaws.com/uifaces/faces/twitter/hebertialmeida/128.jpg"}],"ad":{"company":"StatusCode Weekly","url":"http://statuscode.org/","text":"A weekly newsletter focusing on software development, infrastructure, the server, performance, and the stack end of things."}}

Example 1: I would like to check the full response size is equal to or more than 1000 bytes. If it is less than 1000 bytes , then the sampler should fail.

So the option I choose: Apply To as "Main Samples and Sub-Samples" and Response Size Field to Test "Full Response" option and size in bytes is "1000" and Types of comparison is ">=".

Response for the sampler is shown below. The size of the response is 1954 which is greater than 1000. Hence, the assertion is passed.

Example 2: I would like to check the full response size is equal to or less than 1000 bytes. If it is more than 1000 bytes , then the sampler should fail.

So the option I choose: Apply To as "Main Samples and Sub-Samples" and Response Size Field to Test "Full Response" option and size in bytes is "1000" and Types of comparison is "<=".

Response for the sampler is shown below. The size of the response is 1954 which is greater than 1000. Hence, the assertion is failed.

Based on your need, you can change "Apply to" option, "Response Size Field To Test" option and "Type of Comparison" option and do the assertion. 

In general, size assertion will be useful when you are downloading files/videos/music in your Jmeter script.

4. Duration Assertion

Duration assertion is to check the server responds within a reasonable amount of time. My personal opinion is that this assertion is more like performance alert than assertion.

To add size assertion in the test plan, refer the below snapshot (Right click on Sampler -> Add -> Assertions -> Duration Assertion).

Let us use the same example to validate duration assertion.

Example 1: I would like to check if the response time is less than 1000 milliseconds. If it is more than 1000 ms, then the sampler should fail.

So the option I choose: Apply To as "Main Samples and Sub-Samples" and Duration in milliseconds "1000" .

Response for the sampler is shown below. The response time (Load time) is 650 ms which is less than 1000 ms. Hence, the assertion is passed.

Example 1: I would like to check if the response time is less than 150 milliseconds. If it is more than 150 ms, then the sampler should fail.

So the option I choose: Apply To as "Main Samples and Sub-Samples" and Duration in milliseconds "150" .

Response for the sampler is shown below. The response time (Load time) is 576 ms which is greater than 150 ms. Hence, the assertion is failed.
Simple 😀. Isn't it??

No comments:

Post a Comment

Linux Series - SED Utility/Package - 4. Deleting Lines

Let’s explore sed’s explicit delete command, which you specify by using the option 'd'. Again, we are using the sample file named &#...