Martkos IT Ltd

View Original

JMeter Test Fragment

JMeter allows you to rapid build test plans. Typically, you would add a Thread Group, Sampler and Listener, but there would be a degree of duplication as you call the same components. Test Fragments allow you to modularise components within the test plan and reuse them.

Test Fragments are only executed through a Module Controller or Include Controller. This allows you to create code blocks and execute them on demand.

A Test Fragment can be created anywhere in the Test Plan but for clarity we create it directly at the top of the test plan. To organise and group the components we add a Simple Controller. This itself does little other than act as a container. Then we add a HTTP Request Sampler.

The HTTP Request Sampler we have created will not be executed. So we create a Thread Group and under that a Module Controller (or Include Controller). The Module Controller acts as a shortcut to an element so we select the Simple Controller we created earlier. Now when we execute the test plan the module controller will be executed which in turn will execute the Simple Controller and HTTP Request Sampler in the Test Fragment.

When creating test fragments and subsequent calls, it makes sense to name them uniquely. Then when you call them through a Module Controller you can identify. In this example we’ve renamed the test fragment to “APIs”, then the Simple Controller “Authentication” and the HTTP Request Sampler “Authentication”. This is the same for the “Report” API.

Using Test Fragments gives you a great control over the components and how they are executed in your test plan. They also reduce the amount of duplication which can help to keep the size of the test plan down.

FURTHER READING

Test Fragments

Manage Large Test Plans