Assertions
In JMeter, the Assertion is used to validate the response to the request you sent to the server. At run time, the Assertion is a process in which you compare the expected result to the actual result of the request. If you need to apply Assertion to a specific Sampler, make it a child of that Sampler. The image below shows how to add an Assertion to your JMeter Test Plan.

Below given is the list of all the Assertions JMeter provides −
- Response Assertion
- Duration Assertion
- Compare Assertion
- Beanshell Assertion
- BSF Assertion
- JSR223 Assertion
- BeanShell Assertion
- MD5Hex Assertion
- HTML Assertion
- XPath Assertion
- Size Assertion
- XML Assertion
- XML Schema Assertion
- SHMIME Assertion
- JSON JMESPath Assertion
As we can see, many Assertions are used in JMeter but don’t get intimidated. Only a few of them are used commonly, and we will look into them in detail.
Commonly used JMeter Assertions
This section will discuss the need and way to use the most frequently used Assertions in a JMeterTest Plan. Let us explore them one by one.
Response Assertion
We use response Assertions to check the patterns in the server's response body. Various pattern-matching rules, such as contains, matches, equal, etc., can be applied to validate the response. These comprise the response Assertion's fundamental components.

Duration Assertion
The Duration Assertion measures the speed with which each server response was obtained. Any response that takes more than the user-specified number of milliseconds is labeled as a failed response.

The image above shows the duration Assertion window.
Size Assertion
The expected number of bytes is confirmed using the size Assertion method. We can provide the anticipated size in bytes and check using various comparisons like >,<, =, etc. The following elements make up JMeter's Size Assertion.

XML Assertion
This Assertion is used to determine whether or not the XML document returned by the server is accurate.
These are the fundamental components of an XML Assertion.
HTML Assertion
This Assertion is used to validate the HTML provided by the server as part of the response. The essential parts of the HTML Assertion are listed below.

BeanShell Assertion
We can validate the results of a Sampler using BeanShell Scripting and the BeanShell Assertion. The following are the fundamental components of a BeanShell Assertion in JMeter.

Must Read Apache Server
Frequently Asked Questions
What purposes do JMeter Assertions serve?
JMeter uses Assertions to verify the server's response to your request. The Assertion is a technique to compare the request's actual outcome to what was anticipated at run time. If an Assertion needs to be applied to a specific Sampler, add it as a child of that Sampler.
JMeter employs which programming language?
JMeter uses the Groovy language as a scripting language. Groovy has proven to be a powerful yet lightweight language in terms of performance in improving JMeter's functionality.
In JMeter, what does JSON Assertion mean?
The Response Assertion has been extended to include JSON. It seeks to make it easier to navigate JSON answers so that data integrity checks can be completed quickly. JMeter will throw an error if the JSON path specified in the Assert JSON Path exists parameter does not exist.
Can we add an Assertion to any Sampler?
Yes. We can add Assertions to any Sampler.
Conclusion
This blog discussed Assertions in JMeter, an important element of the JMeter Test Plan. We started by discussing the JMeter test Plan and then discussed the JMeter Assertion and its types. We hope this blog added to your knowledge of JMeter.
For more information on JMeter, Refer to our other articles-
Please refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. And also, enroll in our courses and refer to the mock test and problems available. Have a look at the interview experiences and interview bundle for placement preparations.
Keep learning, and Keep Growing!