Assertions are the test plan elements that are used to validate the sampler response recieved from the server. In order to test a sampler response, we add different assertions to the sampler requests as child. If an assertion fails, the sampler response is marked as failure and the same gets reflected in the test results like in case of aggregate report listener.How to add an Assertion-
Assertions are needed in performance test scripts to validate that the response recieved from server is correct and is not affected by increasing 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 spefied 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.