Assertions in JMeter

What are Assertions?

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-
Right Click on a Sampler Request -> Hover over Add -> Hover Over Assertion -> Click on the required Assertion
Assertions in JMeter

Why do we need assertions?

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.


Assertions provided in JMeter

Response Assertion

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

HTML Assertion

The HTML assertion is used to check the HTML syntax of the response.


Size Assertion

The size assertion is used to validate the size of the response with a specified value in bytes.


Compare Assertion

The Compare Assertion is used to compare sampler results.


BSF Assertion

The BSF Assertion is used to validate the sampler result using BSF scripting.


Duration Assertion

The duration assertion is used to validate that the sampler request gets processed within a spefied amount of time.


XML Assertion

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.


XPath Assertion

The XPath assertion is used to validate the response using XPath expressions.


MD5Hex Assertion

The MD5Hex Assertion is used to validate the sampler result by checking its MD5Hex hashcode against a hashcode value provided.


SMIME Assertion

The SMIME Assertion is used to validate the body of a MIME message.


JSR223 Assertion

The JSR223 Assertion is used to validate the sampler result using JSR223 scripting.


Reference

Apache JMeter User Manual