JMeter – Assertion

Since performance testing falls under the non-functional testing category but getting a correct functional response is always the first priority. All the performance testing tools have such a feature to validate the response coming from the server and raise a warning or error when the validation fails. JMeter also has a special element called ‘Assertion’ to validate the response on the basis of pre-defined conditions. Based on the validation result, it makes a decision to pass or fail the sampler. Basically, the assertion elements are a part of the post-processor family because they execute after getting the response from the server and then compare the expected result with the actual result.

Assertion elements are scope specific. They have local as well as global scope, depending on the place where they get added. If you add an assertion as a child element of a test plan then its scope becomes global and this assertion will validate all the requests. On the other hand, if you add it under a sampler, only that particular sampler’s response will be validated.

You can view assertion results by adding ‘Assertion Listener’ to the Thread Group.

Figure 01: JMeter Assertion

Possible Parent element(s) of Assertion:

You can add an Assertion under the following elements:

  1. Test Plan
  2. Thread Group
  3. Test Fragment
  4. Sampler
  5. Logic Controller
  6. Non-Test Element

Possible Child Element(s):

  • NA

You can not add any element under an ‘Assertion’ element. Hence it does not have any child element.

List of Assertion elements in JMeter:

  1. Response Assertion
  2. Duration Assertion
  3. Size Assertion
  4. XML Assertion
  5. BeanShell Assertion
  6. MD5Hex Assertion
  7. HTML Assertion
  8. XPath Assertion
  9. XPath2 Assertion
  10. XML Schema Assertion
  11. JSR223 Assertion
  12. Compare Assertion
  13. SMIME Assertion
  14. JSON Assertion
  15. JSON JMESPath Assertion

You may be interested: