Listeners and Assertion for JMeter

So, till now we have seen few samplers sending requests to the server but haven’t analyzed the response yet. Performance testing is all about analyzing server responses in various form and then presenting the same to the client.

Listeners are used to display the results of test execution so that testers get to know the stats. We have around 15 listeners in Jmeter but mostly used ones are table, tree, and Graph.

View Results in Table:

This is the most commonly used and easily understandable form of listeners. It displays the result in form of table with some important performance parameters.

Listeners can be added directly under Test plan or under a sampler. The difference is, when you add listener under a sampler, it will show the results of that sampler only. If we add sampler directly under the test plan, it displays the result for all the Sampler up in the hierarchy.

The screenshot below for your reference:
  • Latency: It is the time when the first piece of information is received i.e. the first byte of data is received
  • Connect Time: It is the time taken to establish connection with the server
  • Sample Time: It is the time taken to receive complete data
  • Sample – Sequence of sample number
  • Bytes – Size of data received.
View Results in Tree:

This is another most commonly used listeners and provides detailed information with request and response. One can also view the HTML page rendered in response apart from viewing Json, XML, Text, RegEx.

It is very useful as testers can put assertions on the response received to be ensured that the test passed. Jmeter results still show “Pass” even if the response is not desired.

For Example: Say, we hit HTTP request on any website www.xyz.com and in response we expect or in simple words, when we hit this page company’s home page opens with its name. If we haven’t put assertion, Jmeter will still display results since the hit has gone to the server.

Please see below to know the format of results:

 Listeners

So, till now we have seen few samplers sending requests to the server but haven’t analyzed the response yet. Performance testing is all about analyzing server responses in various form and then presenting the same to the client.

Listeners are used to display the results of test execution so that testers get to know the stats. We have around 15 listeners in Jmeter but mostly used ones are table, tree, and Graph.

View Results in Table:

This is the most commonly used and easily understandable form of listeners. It displays the result in form of table with some important performance parameters.

Listeners can be added directly under Test plan or under a sampler. The difference is, when you add listener under a sampler, it will show the results of that sampler only. If we add sampler directly under the test plan, it displays the result for all the Sampler up in the hierarchy.

The screenshot below for your reference:
  • Latency: It is the time when the first piece of information is received i.e. the first byte of data is received
  • Connect Time: It is the time taken to establish connection with the server
  • Sample Time: It is the time taken to receive complete data
  • Sample – Sequence of sample number
  • Bytes – Size of data received.
View Results in Tree:

This is another most commonly used listeners and provides detailed information with request and response. One can also view the HTML page rendered in response apart from viewing Json, XML, Text, RegEx.

It is very useful as testers can put assertions on the response received to be ensured that the test passed. Jmeter results still show “Pass” even if the response is not desired.

For Example: Say, we hit HTTP request on any website www.xyz.com and in response we expect or in simple words, when we hit this page company’s home page opens with its name. If we haven’t put assertion, Jmeter will still display results since the hit has gone to the server.

Please see below to know the format of results:

 Assertions

Till now, we have covered how JMeter hits the server and how the responses are displayed via listeners. To ensure that the response received is correct and as per expectation, we need to add assertions. Assertions are simply validations which we need to put on responses to compare the results.

Below are the types of assertions commonly used:
  • Response Assertion
  • Duration Assertion
  • Size Assertion
  • XML Assertion
  • HTML Assertion
Response Assertion

In Response Assertion, we can add our own pattern strings and then compare them with the responses received from a server. For example, you all know response code is 200 when any request returns some response successfully. So, if we add pattern string “Response Code = 202” then the test case should fail.

Please refer below screenshots to add Response Code assertion.

Now, when the test runs it shows the result with Red Color indicating that the Assertion results are failed.

Duration Assertion

Duration Assertion is very important and validates that the server responded within a given amount of time. This can be used in scenarios where we need to sample 100 requests and ensure that every time response is received within the benchmarked limit.

Case: 10 users are concurrently hitting “google.com” server and Duration Assertion is set to 1000ms.Please see below screenshots:

XML Assertion validates if response data has correct XML document in it and HTML Assertion verifies the HTML syntax of the response received from a server.

Leave a Reply

Your email address will not be published. Required fields are marked *