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-
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.
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-
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.
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.