Site icon Vinsguru

JMeter – How To Run Multiple Thread Groups in Multiple Test Environments

Overview: 

As part of performance testing,  I had to come up with performance test scripts for various use cases / business workflows for our application. When I design my performance test scripts, I will ensure that I have reusable test scripts as mentioned in this article.

JMeter – How To Create Reusable & Modular Test Scripts

If you have not read this article already, I would request you to read the article first and proceed with this article!  As part of the above article, you can learn how to properly design your performance test scripts / test plan.

In a high level, I maintain a reusable ‘test script’ modules under ‘Test Fragment’. Then I use Module Controller to call specific modules to create the workflow.

I also create multiple ‘Thread Groups’ for each business functionality / workflow.

Once you have a test plan as mentioned above with multiple thread groups,  then let’s see how we could maintain the JMeter test plan using Property files & running a specific thread group on a specific environment in this article!

Creating a Simple Test Plan:

Let’s consider an application with below business functionalities.

  1. New User Registration
  2. User Login & Order Creation
  3. User Login & Product View
  4. Existing Order Edit/Cancel
  5. User Search

 

Lets also assume that we already came up with performance test plan with multiple thread groups as shown above. Each thread group will perform the specific functionality.

Sample Performance Test Requirement:

Now Lets assume we have performance requirements like,

  1. Test each module independently (just run 1 thread group at a time).
  2. Test combination of modules (more than 1 thread group / all).
  3. Test in different environment (same test in different environment – In my project, I also run the same test in 2 different environments – QA & Staging).

Parameterizing Environment Details:

# QA.properties

test.environment.hostname=10.11.12.14
test.environment.port=8080
test.environment.protocol=http
# Staging.properties

test.environment.hostname=10.11.12.13
test.environment.port=443
test.environment.protocol=https

 

 

 

Note:

Now your test plan is modified to run the script on any given test environment.

Parameterizing Thread Group Details:

# Anonymous User - Product Search

group1.usercount=10
group1.rampup=10
group1.duration=600

# New User Registration

group2.usercount=10
group2.rampup=10
group2.duration=600

# User Login & Order Creation

group3.usercount=10
group3.rampup=10
group3.duration=600

# User Login & Existing Product View

group4.usercount=10
group4.rampup=10
group4.duration=600

# BackOffice Admin User Activities - Existing Order Edit/Cancel

group5.usercount=10
group5.rampup=10
group5.duration=600

 

Note:

If the Thread Group user count is 0, JMeter can not execute the Thread Group. By updating thread group user count property to 0, a thread group can be disabled.

# Anonymous User - Product Search - Only

# Anonymous User - Product Search

group1.usercount=100
group1.rampup=100
group1.duration=3600

# New User Registration

group2.usercount=0
group2.rampup=0
group2.duration=0

# User Login & Order Creation

group3.usercount=0
group3.rampup=0
group3.duration=0

# User Login & Existing Product View

group4.usercount=0
group4.rampup=0
group4.duration=0

# BackOffice Admin User Activities - Existing Order Edit/Cancel

group5.usercount=0
group5.rampup=0
group5.duration=0

So, I create multiple property files to control specific thread group execution.

Add one more ‘Property File Reader’ to read specific module you are interested in executing.

Controlling Thread Group & Environment via Command Line:

Rest is simple!!!

jmeter -n -t test.jmx -l result.jtl -Jenvionment=staging -Jmodule=all-module
jmeter -n -t test.jmx -l result.jtl -Jenvionment=QA -Jmodule=all-module
jmeter -n -t test.jmx -l result.jtl -Jenvionment=staging -Jmodule=ordercreation-only

To run registration module on QA,

jmeter -n -t test.jmx -l result.jtl -Jenvionment=QA -Jmodule=registration-only

 

Triggering Thread Groups via Jenkins:

If we use Jenkins to run our test, these test environment & module can be drop down list containing the possible values & passed as parameters from Jenkins to JMeter.

Thus, We can run specific thread group on specific environment without modifying the JMeter test as given below.

More details on JMeter-Jenkins integration can be found here.

Summary:

By properly designing the JMeter test plan with reusable test scripts, multiple thread groups and Property File Reader etc, we are able to control specific thread group execution at run time.

So we can focus on performance related issues for a specific module instead of running the whole test plan every time.

 

Happy Testing & Subscribe 🙂

 

 

Share This:

Exit mobile version