Skip to content
  • ZipCode Api
  • Blog
  • About RedLine13
RedLine13
RedLine13
Primary Navigation Menu
Menu
  • Start Testing
  • Demo
  • Pricing
  • JMeter
  • Partners
  • Docs
    • Documentation Home
    • AWS Set Up for load testing
    • AWS Approval for Large Tests
    • PHP, NodeJS, Python Load Tests
    • Scalability
    • Jenkins Plugin Setup
    • Premium Features
    • Knowledge Base

Using Test Fragments in JMeter Tests

By: David Koziel

Using Test Fragments in JMeter Tests

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.

An example of a test plan fragment that combines related tasks
An example of a test plan fragment that combines related tasks.

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:

An example of a JMeter test using Test Plan Fragments and Module Controllers to reuse test logic
An example of a JMeter test using Test Plan Fragments and Module Controllers to reuse test logic.

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:

View Results Tree output showing execution of a JMeter test with reusable Test Plan Fragments
View Results Tree output showing execution of a JMeter test with reusable Test Plan Fragments.

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!

2025-02-13
Previous Post: Step-by-Step Guide to Testing with JMeter
Next Post: JMeter Rotating JTL Listener

Recent Posts

  • JMeter XML Format Post Processor
  • Order of Elements in JMeter
  • The JMeter Synthesis Report
  • Using the JMeter Plugins Manager
  • JMeter Rotating JTL Listener

Related

  • JMeter XML Format Post Processor
  • Order of Elements in JMeter
  • SAML Configuration with Azure AD and RedLine13
  • SAML Configuration with OKTA and RedLine13
  • SAML Configuration with Google and RedLine13
  • The JMeter Synthesis Report
  • Using the JMeter Plugins Manager
  • JMeter Rotating JTL Listener
  • Using Test Fragments in JMeter Tests
  • Step-by-Step Guide to Testing with JMeter

© RedLine13, LLC | Privacy Policy | Contract
Contact Us: info@redline13.com

Designed using Responsive Brix. Powered by WordPress.