• info@helpingtesters.com
  • helpingtesters

Assertions in JMeter

September 10, 2017 JMeter Tutorial
JMeter Assertions, JMeter Assertions Example,JMeter Assertions Tutorial, apache jmeter assertions

After creating the end to end request with reports comes Jmeter Assertions. JMeter Assertions help us to validate data in response. They help to reduce manual effort of checking each and every response and analyzing their values. Assertions are added as part of the requests. One can run thousands of requests and view their results using JMeter Assertions at one go. 

Adding JMeter Assertions

Do right click on Thread Group > Add > Assertions > Select any assertion from the list

→Complete list of JMeter Tutorial Series

Types of JMeter Assertions

There are multiple ways in which a response of a request can be validated.

⇒ Response JMeter Assertions

This type of assertion validates information in “Response Data” and “Sampler Result”.

  • Text Response: We can validate using any data in “Response Data”.
  • JMeter Assertions Pass: When assertion passes then test run will be highlighted in green color.
  • JMeter Assertions Failure: When the assertion fails then test run will be highlighted in red color.  One can double click on failed request and it will open Response assertion. Once it is clicked, the user can see the assertion result with the message detailing why this particular request has failed.

 

  • Response Code: Validates the response code returned in the Response Data.

  • Response Code: 200 is returned for the valid response.
  • Patterns to Test: The code mentioned in “Response Assertion” and returned in “Response Data” is matched. If it matches then JMeter Assertions passes else it fails.

Pattern Matching Rules

These rules decide the matching criteria between “Patterns to Test” and “Response Data”.

  • Contains: If selected, this rule checks that whether “Response Data” contains “Patterns to Test” or not.
  • Matches: If selected, this rule matches the “Response Data” and “Patterns to Test”.
  • Equals: If selected, this rule checks that “Response Data” and “Patterns to Test” should equate.
  • Substring: If selected, this rule checks that whether “Patterns to Test” is a substring of “Response Data” or not.

⇒ Duration JMeter Assertions

It checks whether the response is received in the expected amount of time or not. In this assertion, we can validate the time in which the response is received.

Value mentioned in “Duration in milliseconds” is the maximum time that a request should take to return the response. For example: If value mentioned in “Duration in milliseconds” is 100 and actual request took 350 ms to return the response then assertion will fail as shown below.

It means that the request was expected to return the response in 100ms but it took 350ms which is higher. Hence, Response assertion message also says that: Operation lasted too long; it took 350 ms, but should not have lasted longer than 100 ms.

On the other hand, if value mentioned in “Duration in milliseconds” is 350 and actual request took 100 ms to return the response then assertion will pass and success will be returned.

 

Size JMeter Assertions

One can check the expected amount of size in bytes using this assertion. The value of size in bytes can be fetched from listener like “View Results in Table” > “Bytes” column for passing request.

Value mentioned in size in bytes can be asserted with “Type of comparison”. For example, the Expected value is 5 and size in bytes are mentioned as 7 with “Type of comparison” as “=” in that case assertion will fail. However, if “Type of comparison” is specified as “<” then assertion will pass.

 

⇒ XML JMeter Assertions

Validates XML in response. It validates that XML is returned in response or not.

 

If XML is not returned in the response then XML Assertion will fail with below error: XML Assertion: Content is not allowed in prolog

 

⇒ HTML JMeter Assertions

This assertion checks for the format of response returned like HTML, XML, XHTML

If the format of response matches with expected format then, Sampler name is returned in listener > Assertion results.

 

In case of failure, HTML Assertion will return the error like below :

 

One can specify the Threshold of error in “Error Threshold” and “Warning Threshold” fields. For example, if 5 is specified then, HTML assertion will fail if errors > 5 else it will pass.

About the author

Ankita Dawar author

Ankita has worked on different types of testing like Manual, Automation, Performance testing.  She likes to learn about new tools in market that help to make testing easier and interesting. Testing is her passion due to versatile areas it offers.

Leave a Reply

Your email address will not be published.