Back to Blog
Organize your Samplers efficiently using JMeter: Module Controller

Organize your Samplers efficiently using JMeter: Module Controller

Patrick Kievit

When I started creating performance tests with Apache JMeter, I quickly realized I didn't know much about the features that come with the package. I'm writing this piece, especially for those that google first instead of reading manuals. Like myself.

Obviously, there are many ways to organize your tests. My main focus is to show you the concept of the Module Controller. I'm jumping straight to the subject, using the Module Controller with Apache JMeter.

Duplication Nightmare

I wanted to create a load test with two scenarios. One scenario for accessing user pages and the second scenario to access a customers page. I started off with a single thread group to simulate the first scenario, with a particular number of users, achieving X number of page visits. So far so good.

After that I created a second thread group and started copying samplers that were already created such as Login, Homepage and Logout samplers. The idea of duplicating everything started to bug me.

Test plan structure

In this image you can see the duplicate samplers that I was creating.

I pictured myself having to update my samplers after a software change. It would require me to update all copied samplers. Increasing maintenance efforts which in my opinion should be unnecessary. I started looking for a solution.

An “include” crossed my mind which eventually lead me to using the Module Controller.

What is a Module Controller?

The Module Controller enables you to include, or target, Controllers and Test Fragments. It allows you to avoid duplicating Samplers and efficiently use Samplers throughout your tests scenarios.

Group Samplers using Test Fragments

First, create a Test Fragment. Use Test Fragments to group samplers.

Group samplers

Create a Test Fragment by right clicking Test Plan

Second, add your samplers to test fragment. I'm creating a Test Fragment for a HTTP sampler accessing a particular screen named Users Overview.

Create a test fragment

Create a HTTP sampler by right clicking the Test Fragment.

Create a Thread Group

We are going to build our test scenario. Third, create your Thread Group. Which will reside on the same level as Test Fragments.

Create a thread group

Create a Thread Group by right clicking Test Plan. This is where you can configure the number of virtual users for your scenario.

Now we have created a test fragment with a sampler. And a Thread group.

how it looks

Currently, the Thread Group is empty and not doing anything when the test is executed.

Create a Module Controller

The Thread Group does not have anything to do yet. Fourth, add a Module Controller to the Thread Group.

create a module controller

Create a Module Controller by right clicking the Thread Group.

Target a Test Fragment

The Module Controller can target an element. Fifth and last, target your created Test Fragment. Now the Thread Group has something to do, which is navigating to the Users Overview screen.

target a test fragment

Select your Test Fragment.

Final Result

This way I have configured my two test scenarios.

final result

All Samplers are separated in Test Fragments and my two scenarios are pointing to unique Samplers.

I've reached my goal: the Samplers in the Test Fragment are now run by the Module Controller. Now I only have unique Samplers. Used by different scenarios.

Having unique Sampler names will help you generate clear performance test reports.

Some tips for start using a Module Controller

“When code causing failures is copied, the failures may continue to exist if the developer is not aware of such copies.”

1. Avoid Duplicating samplers and Re-Use samplers.

  • Group Samplers in Test Fragments.
  • Target  Test Fragments one or multiple times as you desire.

2. Efficiently built flows for different Thread Groups.

  • Target Test Fragments in a specific order to build your scenarios.

Now Try it Yourself

  1. Create a Test Fragment
  2. Create a Sampler to the Test Fragment
  3. Create a Thread Group
  4. Create a Module Controller inside the Thread Group
  5. Target your Test Fragment inside your Module Controller

You are now able to organize your tests efficiently using the JMeter Module Controller.

I hope you’ve enjoyed reading this article.

Share on social media: 

More from the Blog

COVID-19 & IT investment - Prevention is better than cure

At a time when we are more reliant on our IT systems than ever - from helping our businesses to flourish, allowing us to work from home, shopping online, improving our lifestyles - how do we make our IT systems safer and more resilient?

Read Story

SAP Activate – What it is & Why You would use it?

What is SAP activate? Activate is SAP’s implementation toolkit. It is more than just a methodology. It’s not pure Agile, not really Waterfall, it is somewhere in between...

Read Story

Software quality: a mind game

Why many technology initiatives are failing? Tools are necessary but not sufficient. Software quality is a mind game: the right mindset is the key to success. Read the story of René, Test manager in Province Noord-Holland.

Read Story