Updated March 30, 2023
Definition of JMeter Response Assertion
JMeter is an open-source tool to perform load and performance testing on the application. JMeter provides the different controllers and functions to perform testing. In which that response assertion is one of the functionalities that are provided by the JMeter. Basically, the assertion is used to validate the response of the request sampler that we sent to the server. In another word, we can say response assertion is used to validate the expected and actual result of the sampler and its running time. If we want to add assertion on the specified sampler, then it acts as a child of that sampler request.
Overview on JMeter response assertion
For those of us who work with JMeter and execution tests, we know the significance of adding approvals to all HTTP Requests. Approvals are not only a method for affirming that the server is reacting true to form, yet they additionally check that the content we are creating is going about as it ought to, meaning, it is reenacting the client conduct as it was planned.
For instance, assuming running our content on the framework infers that a record is made in the information base; we need to guarantee that subsequent to running the content, the record has to be sure been made and that the content doesn’t say everything went without a hitch on the off chance that it didn’t really make it. That would be an illustration of an awful decision of an affirmation or approval of our solicitations.
We need to keep away from bogus negatives and misleading up-sides. Here is a survey of what those mean:
- Positive: The test says there is a blunder when there truly isn’t one and afterward we lose time searching for the reason for the mistake until we understand that the mistake was simply in the test, or in the climate, or the information, and so on
- Negative: There are blunders however they are not found. Since they were not found, we accept that these highlights have been completely covered and they are sans bugs in spite of the fact that they are not.
How to use JMeter response assertion?
Now let’s see how we can use JMeter response assertion as follows.
First, we need to create a Test Plan in JMeter as shown in the following screenshot.
Now add the Thread Group inside the Test Plan with the sample, here we add HTTP Request sampler as shown in the following screenshot as follows.
Now we need to add the listener to view the output, here we add the view result tree listener as shown in the following screenshot as follows.
Now everything is fine, save the Test Plan and run it, the final result of the above Test Plan is shown in the following screenshot as follows.
Now is the time to add a response assertion for the Test Plan, so follow the following step as follows.
1. First we need to select the sample.
2. Right-click on the element and click add and select response assertion
After clicking on response assertion we got a new screen as shown in the following screenshot as follows.
In the above screenshot, we can see different input fields, so as per our requirement we can fill that field.
In this example, we select the main sample only and contain the text option as shown in the following screenshot as follows.
After execution of the Test Plan we can see the result into the view result tree listener as shown in the following screenshot as follows.
Here we can set the different assertions as per our requirement such as response code, response message, request header, etc.
JMeter response assertion configure
Now let’s see how we can configure the response assertion in JMeter as follows.
The response assertion tab consists of the different fields as follows.
- Name: Name means assertion name and it depends on the user.
- Comments: As per our requirement we can give the comments to the assertion.
- Apply to: It contains a different subfield and it is used to define where we want to apply assertion.
1. the Main sample only: it is used to apply the response of the main request.
2. Subsample only: It is used to redirect requests only to the specified scope.
3. JMeter Variable: On the off chance that given example string esteem assumes to be accessible in any JMeter variable then you really want to choose this choice and specified variable name as for text field.
Field of Test: Here we can define the pattern and it has different subfields as follows.
1. Text Response: It is used to search specific text patterns and it is not included in the search scope.
2. Response Code: JMeter checks the response code and validates it.
3. Text: It is used to search specific text patterns and validate it.
4. Response Header: if we need to validate the herder part of the request then we can use this option.
5. URL Sampled: It is used to validate the URL
Pattern Matching Rule: If we want to set the rule to match any specified pattern then we can use this option.
Custom failure message: Here we can custom message which is displayed after the failure of assertion.
JMeter response assertion type
Now let’s see different types of response assertion in JMeter as follows.
1. Duration Assertion: If want to add the duration to ensure that the response fully comes with the expected time at that time we can use duration assertion. Sometimes requests take more time than we can utilize this type.
2. Size Assertion: It is used to set the limit of response. The size is too large or too small that causes the transaction.
3. Compare Assertion: If we want to compare the expected and actual results then we can set this type.
4. File Type Assertion: If we need to check if a file is valid or not at that time we can use this type.
We hope from this article you learn more about JMeter’s response assertion. From the above article, we have taken in the essential idea of JMeter response assertion and we also see the representation and example of the JMeter response assertion. From this article, we learned how and when we use the JMeter response assertion.
This is a guide to JMeter Response Assertion. Here we discuss the Definition, Overview, configuration, How to use JMeter response assertion, Examples with code implementation. You may also have a look at the following articles to learn more –