What are Assertions?
Assertions in JMeter are the test plan elements that are used to validate the response received from server for a particular sampler request. In order to test a sampler response, we can add different assertions to the sampler requests as child. If an assertion fails, the sampler request is marked as failed and the same gets reflected in the test results listeners like – aggregate report listener.How to add an Assertion-
Right Click on a Sampler Request -> Hover over Add -> Hover Over Assertion -> Click on the required Assertion
Why do we need assertions?
Assertions are needed in performance test scripts to validate that the response received from server is correct and is not affected by increasing the load on the server.
The assertions are also helpful in doing functional testing of different kinds of applications by comparing the actual and expected output.
Assertions provided in JMeter
The response assertion used in test scripts to validate a pattern in the response body, header, code, message etc. There are different pattern matching rules to validate the response like-
- Contains – If the response text contains the regular expression to be matched
- Matches – If the whole response text matches the regular expression
- Equals – If the whole response text matches the pattern(not regular expression but the pattern string)
- Substring – If the response text contains the pattern(not regular expression)
- Not – To check that the pattern is not present in the response text
The HTML assertion is used to check the HTML syntax of the response.
The size assertion is used to validate the size of the response with a specified value in bytes.
The Compare Assertion is used to compare sampler results.
The BSF Assertion is used to validate the sampler result using BSF scripting.
The duration assertion is used to validate that the sampler request gets processed within a specified amount of time.
The XML assertion is used to validate that the response follows a valid XML syntax.
XML Schema Assertion
The XML Schema Assertion is used to validate the response against a specified XML schema.
The XPath assertion is used to validate the response using XPath expressions.
The MD5Hex Assertion is used to validate the sampler result by checking its MD5Hex hashcode against a hashcode value provided.
The SMIME Assertion is used to validate the body of a MIME message.
The JSR223 Assertion is used to validate the sampler result using JSR223 scripting.
That’s all we have in this section, please share it with your friends and colleagues. Check out the complete JMeter tutorial here.
Apache JMeter User Manual
Kuldeep is the founder and lead author of ArtOfTesting. He is skilled in test automation, performance testing, big data, and CI-CD. He brings his decade of experience to his current role where he is dedicated to educating the QA professionals. You can connect with him on LinkedIn.
1 thought on “Assertions in JMeter”
Thread i select only one user
Ramp uo select one time and loop count is also one user
try to check my landing page selected sampler https but getting in response side 401 error yes i am not using recording button not allow to my client window taking script f12 copy curl and paste in j meter tool after that run the test case not getting out put tc failed could you help me as soon as possible or dont mind i am sharing my cont 9380014255