Assertions are Test plan elements in JMeter used to test the response received from the server. Assertions assist in testing that the value returned is matching the expected value. If the assertion fails the sampler is marked as filed and is displayed in the listener. Assertions are applicable to all samplers which are in scope. To limit an assertion to a single sampler we ned to add it as child element.
Add an assertion:
Right Click on Thread Group → Add → Assertion→ Select the required Assertion
JMeter supports different types of assertions like:
- Response Assertion
The response assertion is used to validate a pattern in the response. Different pattern matching rules to validate the response are as below:
- Contains – validates if the response text contains the regular expression to be matched
- Matches –validates If the whole response text matches the regular expression
- Equals – validates If the whole response text matches the pattern (not regular expression but the pattern string)
- Substring –validates If the response text contains the pattern (not regular expression)
- Not – Validates that the pattern is not present in the response text
- HTML Assertion -Validates the HTML syntax of a response
2)Size Assertion
The size assertion is used to validate the response in bytes against a specified value.
3)Compare Assertion
The Compare Assertion is used to compare sampler results.
4)BSF Assertion
The BSF Assertion is used to validate the sampler result using when BSF scripting.
5)Duration Assertion
The duration assertion is used to validate that the sampler request gets processed within a specific time limit.
6)XML Assertion
It is used to validate that the server response has a valid XML syntax.
7)XML Schema Assertion
It is used to validate the response against a specified XML schema.
8)XPath Assertion
It is used to validate the response using XPath expressions.
9)JSR223 Assertion
It is used to validate the sampler result when using JSR223 scripting.