Test plan design, while not always application programming per se, definitely shares some concepts of the latter. A common principle of software development is to minimize repeating code. In this article we will show you how Test Plan Fragments can be leveraged in JMeter test plans to reduce repeated elements.
Basics of Test Plan Fragments
In essence, Test Plan Fragments are groups of test logic which can be referenced by various JMeter controllers, that do not otherwise execute on their own. They can contain HTTP Request Samplers and other test plan elements, similar to how Thread Groups act as containers to group related actions.

The usefulness of Test Plan Fragments becomes evident when we have a need to repeatedly call a group of related tasks but also need intervening processes to run in between. This can be even more important when test plan flow has variability or branching logic.
Example Usage of Test Plan Fragments
We can illustrate an example use case for Test Plan Fragments by imagining the following requirements. For a retail ordering system, we need to place a set number of orders, then perform a change of the shipping address, and then place additional orders. This also requires that we log into the target test application with user credentials. If we abstract these steps into fragments, we end up with a test plan which looks as follows:

Here, “Retail Workflow” is an ordinary Thread Group, which contains Module Controllers that reference the Test Plan Fragments as indicated. The “Place 3 Orders” element is a Loop Controller, which as it suggests executes the contained Module Controller three times. “Place 2 Orders” references the same module controller but executes it only twice.
We can add a View Results Tree listener and run this test plan, which produces the following output:

Though this is an illustration of a basic use case, you can achieve much more complicated workflows with drastically reduced repetition of test logic by leveraging reusable Test Plan Fragments.
Did you know that RedLine13 offers a full-featured, time-limited free trial? Sign up now, and start testing today!