Dummy Sampler

A really useful sampler within Apache JMeter is the Dummy Sampler. It provides a localised method of sending a custom request and returning a custom response. Perfect for acting as a stub within the test plan.

Installation

Download plugins-manager.jar and put it into lib/ext directory, then restart JMeter.

The Dummy Sampler is a plugin within JMeter. It is hosted on https://jmeter-plugins.org/wiki/DummySampler/ to install the sampler use the plugin manager. Click on Options > Plugins Manager and then click on “Available Plugins”. Click in the search box and type “dummy sampler”. Click on the checkbox at the side of the “Dummy Sampler” and then click Apply Changes and Restart JMeter.

Usage

The jp@gc - Dummy Sampler contains a variety of configurable including “Response Code”, “Response Message”, “Connect Time”, “Latency”, “Response Time”, “Simulate Response Time”, “Request Data”, “Response Data” and “URL”.

To use it create a test plan, thread group and then the dummy sampler can live anywhere.

An example DummySamplerExample.jmx can be downloaded from the authors pages. The Test Plan uses the Dummy Sampler to generate random response codes. An assertion is then used to pass or fail the the dummy response based on the response code returned.

The example uses the Random function to pick a random prefix number between 1 and 5 followed by a 0 and then and a random suffix between 1 and 5. e.g. 200, 301, 302, 500.

${__Random(1,5)}0${__Random(1,5)}

It introduces a random latency between 1 and 100.

${__Random(1,100)}

Also a random response time between 10 and 1000

${__Random(10,1000)}

Finally, it returns a random number in the response data between 1 and 1000.

Random number:${__Random(1,1000)}

When you execute the test and look at the tree view there will be a mixture of successful and requests that have a response code deemed a failure by the assertion. This would be great where you want to force a failure response code to ensure that your application handles the failure gracefully.

This is only a basic example of the dummy sampler. It can perform for more complex behaviours.

It can be particularly helpful where part of an application are not fully developed such as an API. If the presentation layer was ready for testing you could simply use a dummy sampler in place of the API end point and return a valid response in its place which would allow the remainder of the process to complete.

FURTHER READING

Plugin Manger
Dummy Sampler

Previous
Previous

JMeter Inter-Thread Communication

Next
Next

HAR to JMX File