Open In App

Assertions in JMeter

Improve
Improve
Like Article
Like
Save
Share
Report

There are various test plan elements in JMeter like Thread group, controllers, listeners, timers, assertions, etc. In this article, we are going to learn about assertions. Assertions are used to verify and validate the data of requests that we have sent to the server. Using assertions we can compare the expected result with the actual result. For example, if we want to see a message like the welcome user, then we will add that text in contains column using response assertion. The assertion passes if the given text is present in the response sent by the server or else that request shows an error while executing the test. Here response assertion is one of the assertions that are provided by JMeter. Jmeter supports a wide variety of assertions as mentioned below.

Assertions Provided by JMeter

  • BeanShell Assertion
  • BSF Assertion
  • Compare Assertion
  • Duration Assertion
  • HTML Assertion
  • JSR223 Assertion
  • MD5Hex Assertion
  • Response Assertion
  • Size Assertion
  • SMIME Assertion
  • XML Assertion
  • XML Schema Assertion
  • XPath Assertion

Now we will define a few most commonly used assertions in brief

Response Assertion

Response assertions are used to verify the patterns in the response body received from the server. Different pattern matching rules like contains, matches, equal, etc. can be used to verify the response. These are the basic elements of the response assertion.

 

Size Assertion

Size assertion is used to verify the expected number of bytes. We can add the expected size in bytes and verify with the different types of comparisons like >, <, =, etc. The following are the components of the Size assertion in JMeter.

Size Assertion

 

XML Assertion

This assertion is used to verify if the XML document provided by the server in response is right or wrong. Here are the basic elements of the XML assertion

XML Assertion

 

HTML Assertion

This assertion is used to check the syntax of the HTML given by the server in response. Here are the basic components of the HTML assertion

HTML Assertion

 

BeanShell Assertion

Using the BeanShell Assertion we can validate the result of a sampler using the BeanShell Scripting. The following are the basic elements of a BSF assertion in the JMeter.

BeanShell Assertion

 

Duration Assertion

Duration assertion is one of the commonly used assertions in JMeter. Using duration assertion we can verify if the request is being processed within the given amount of time. Here are the basic elements of a duration assertion in the JMeter.

Duration Assertion

 

Adding Assertions to Test Plan

Adding assertions to the test plan is similar to adding a thread group. The path to adding assertion is as follows test plan/thread group >> Add >> assertions >> required assertions. You can refer to this image also.

Adding Assertions to Test Plan

 


Last Updated : 11 Apr, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads