JMeter – Size Assertion

In JMeter, Size Assertion is mainly used to validate the size of the full response or some part of the response like header, code etc. This assertion helps to identify the throughput-related issue. A simple scenario where you can add size assertion is a file-downloading scenario.

How to add ‘Size Assertion’?

You can follow the below steps:

  1. Select the ‘Sampler’ element whose response size needs to be validated.
  2. Right-click on the sampler
  3. Hover the cursor on ‘Add’
  4. Hover the cursor on ‘Assertions
  5. Click ‘Size Assertion’
JMeter - Size Assertion
Figure 01: Size Assertion

What are the input fields of ‘Size Assertion’?

‘Size Assertion’ has the following input fields:

  1. Name: To provide the name of the assertion.
  2. Comments: To provide arbitrary comments (if any)
  3. Apply to: To define the search scope.
    1. Main sample and sub-samples: In case, the request is redirected then use this option, so that the response will be the sum of both main and re-directed request-response size and can be compared with the expected response size.
    2. Main sample only: This option can be selected when we want to validate the response size of the main sample only.
    3. Sub-samples only: When the request is re-directed and the response size comparison is needed only for the sub-sample (re-directed) method, this option must be selected.
    4. JMeter Variable Name to use: To validate the size of the JMeter variable.
  4. Response Size Field to Test: This option is used to specify the part of the response whose size needs to be validated.
    1. Full Response: It includes both the response header as well as response body size and the sum is compared with the expected size figure given in the ‘Size to Assert’ field.
    2. Response Hearders: Only the size of the response header is compared with the given size. 
    3. Response Code: The size of the response code (around 3 bytes) is compared with the given size assertion.
    4. Response Message: The given size assertion is compared with response message size.
  5. Size to Assert: The expected size of the response needs to be provided in the ‘Size in bytes’ field which is compared with the actual response size using the given condition in the ‘Types of Comparison’ field.
  6. Types of Comparison:  JMeter provides all the possible comparison methods like equal to (=), not equal to (!=), greater than (>), less than (<), greater than or equal to (>=) and less than or equal to (<=) to compare the actual and expected response size. 

Some Key Rules:

  1. Size assertion follows scope policy means if we add size assertion at the transaction level then the assertion is applicable to all the samplers under the same transaction. 
  2. The expected size must be given in bytes.
  3. The expected size value can be parametrized.
  4. You can define Global Size Assertion under the test plan which will be applicable to all the samplers.

You may be interested: