JMeter Global Properties
This article explains how to use Apache JMeter's global variables (properties) to share data across thread groups and create reusable test plans for multiple environments.
Mark
Performance Testing Expert
This post discusses Apache JMeter’s approach to variable scope and demonstrates how to leverage properties for cross-environment testing.
Core Concept
JMeter distinguishes between local variables confined to thread groups and global variables accessible throughout a test plan. If a variable is inside a thread group it will only be visible within it. To share data across multiple thread groups, developers should use JMeter properties instead.
Practical Application
The strategy presented here builds environment-agnostic test plans. Rather than maintaining separate assets for integration, system test, and pre-production environments, developers define prefixed variables:
integration_*syst_*preprod_*
Each prefix precedes configuration parameters including:
- Protocol
- URL
- Port
- Username
- Password
- Proxy settings
Implementation Technique
A JSR223 sampler reads an environment variable and executes conditional logic via a switch statement:
def env = vars.get("environment")
switch(env) {
case "integration":
props.put("protocol", vars.get("integration_protocol"))
props.put("host", vars.get("integration_host"))
props.put("port", vars.get("integration_port"))
break
case "syst":
props.put("protocol", vars.get("syst_protocol"))
props.put("host", vars.get("syst_host"))
props.put("port", vars.get("syst_port"))
break
case "preprod":
props.put("protocol", vars.get("preprod_protocol"))
props.put("host", vars.get("preprod_host"))
props.put("port", vars.get("preprod_port"))
break
}
The code uses props.put() to assign user-defined variable values to global properties based on the selected environment. This approach enables command-line overrides when necessary.
Key Benefit
This methodology reduces testing assets while maintaining repeatability across different deployment stages.
Further Reading
Tags: