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.
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 assertions are also helpful in doing functional testing of different kinds of applications by comparing the actual and expected output.
How to add an Assertion-
step 1:Right Click on a Sampler Request
step 2: Add Assertion and Click on the required Assertion
you can see the same in the screenshot.
The types of assertions in jmeter are response assertion,duration assertion,size assertion,HTML assertion,XML assertion ,compare assertion ,JSR223 assertion etc.
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 specified 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.
No comments:
Post a Comment