JMeter – Duration Assertion

JMeter - Duration Assertion logo

In JMeter, Duration Assertion is mainly used when we have response time NFR and on the basis of those figures, we want to make a sampler or transaction controller pass or fail. It is a simple assertion element where we just need to provide ‘apply to’ and ‘duration’ input.

How to add ‘Duration Assertion’?

You can follow the below steps:

  1. Select the ‘Sampler’ element whose response duration needs to be validated.
  2. Right-click on the element
  3. Hover the cursor on ‘Add’
  4. Hover the cursor on ‘Assertions
  5. Click ‘Duration Assertions”
JMeter - Duration Assertion
Figure 01: Duration Assertion

What are the input fields of ‘Duration Assertion’?

‘Duration Assertion’ has the following input fields:

  1. Name: To provide the name of the assertion.
  2. Comments: To provide arbitrary comments (if any)
  3. Apply to: To define the search scope. 
    1. Main sample and sub-samples: In case, the request is redirected then use this option, so that the response time duration will be the sum of both main and re-directed request response time and can be compared with the expected duration.
    2. Main sample only: This option can be selected when we want to validate the response time of the main sample only.
    3. Sub-samples only: When the request is re-directed and the response time duration comparison is needed only for the sub-sample (re-directed) method then this option needs to be selected.
  4. Duration to Assert: The expected response time duration needs to be provided in the ‘Duration in milliseconds’ field which will be compared with the actual response time duration and a decision will be made. When the actual duration is more than the expected duration then the sampler will be marked as failed whereas when the actual duration is less than the expected duration then the result will be treated as pass. 
Assertion Result
Figure 02

Some Key Rules related to Duration Assertion:

  1. Duration assertion follows scope policy means if we add duration assertion at transaction level then the assertion is applicable to all the samplers under the same transaction. 
  2. Duration should be given in milliseconds.
  3. Duration value can be parametrized.
  4. You can define Global Duration Assertion under the test plan which will be applicable to all the samplers. 

Leave a Reply

Your email address will not be published. Required fields are marked *