Duration Assertion in JMeter
Duration Assertion in JMeter
The Duration Assertion in Apache JMeter tests whether each response is received within a specified time limit. If a response takes longer than the defined time (in milliseconds), it is marked as a failed response.
Example: Setting Up Duration Assertion
Create a Thread Group
- Right-click Test Plan → Add → Threads (Users) → Thread Group
Configure HTTP Request Defaults
- Go to Thread Group → Add → Config Element → HTTP Request Defaults
- Set Server Name as:
example.com
Add an HTTP Request Sampler
- Go to Thread Group → Add → Sampler → HTTP Request
- Rename it to Example Page
- Specify the path of the webpage.
Add Duration Assertion
- Go to Example Page → Add → Assertions → Duration Assertion
- Set Duration in Milliseconds to
2000
Understanding the Duration Assertion
In the above example, JMeter checks if example.com
responds within 1000 milliseconds. If it does, the test passes; otherwise, it fails.
Applying Duration Assertion to Samplers
The Duration Assertion can be added to both:
- Main Samplers
- Sub Samplers
Modifying the Duration for a Failure Scenario
Now, let’s reduce the Duration in Milliseconds to 500
and observe the results.
Viewing the Results
Add a Listener
- Go to Add → Listener → View Results in Table
Now, run the test again. Since the response time of example.com
is usually more than 500 milliseconds, the request is expected to fail.
Duration Assertion Failure Message
When the Duration Assertion fails, JMeter displays a failure message similar to:
HTTP Request
Duration Assertion : The operation lasted too long: It took 1,824 milliseconds, but should not have lasted longer than 500 milliseconds.
You can now check the sample time taken to load example.com
in the test results.
Conclusion
The Duration Assertion helps ensure response time requirements are met. If you have any queries about Duration Assertion, feel free to ask in the comments.