What is Assertion?

Assertions allow you to include some validation test on the response of your request made using a Sampler. They are inserted as a child component of a Sampler. Assertions are particularly necessary in functional testing of your applications, while, in performance testing, you may want to use assertion to ensure the responses you receive.

Why Assertion?

Assertions are used to perform additional checks on samplers.


Types of Assertion in Jmeter

Response Assertion: Lets you add pattern strings to be compared against various fields of the response. The pattern strings are Perl5-style Regular Expressions

Duration Assertion: This tests that each response was received within a given amount of time. Any response that takes longer than the given number is marked as a failed response.

Size Assertion: This tests that each response contains the right number of bytes in it. You can specify that the size be equal to, greater than, less than, or not equal to a given number of bytes.

XML Assertion: This tests that the response data consists of a formally correct XML document. It does not validate the XML based on a DTD or schema or do any further validation.

BeanShell Assertion: Allows the user to perform assertion checking using a BeanShell script.

MD5Hex Assertion: Allows the user to check the MD5 hash of the response data.

HTML Assertion: Allows the user to check the HTML syntax of the response data using JTidy.

XPath Assertion: The XPath Assertion tests a document for well formedness and has the option of validating against a DTD, or putting the document through JTidy and testing for an XPath.

XML Schema Assertion: The XML Schema Assertion allows the user to validate a response against an XML Schema.


Running the tests and analyzing the Assertion results

Assertions allow you to assert facts about responses received from the server being tested. Using an assertion, you can essentially "test" that your application is returning the results you expect it to.

You can add an assertion to any Sampler. For example, you can add an assertion to a HTTP Request that checks for the text, "</HTML>". JMeter will then check that the text is present in the HTTP response. If JMeter cannot find the text, then it will mark this as a failed request.

Add Assertion
Add Assertion

To view the assertion results, add an Assertion Listener to the Thread Group. Failed Assertions will also show up in the Tree View and Table Listeners, and will count towards the error %age for example in the Aggregate and Summary reports.

Add Assertion Results
Add Assertion Results

Assertion Results
Assertion Results