eBook > The JMeter Playbook: Build, Scale, and Optimize Performance Tests
Key Concepts
Before you build your first test, you need to understand the building blocks of every JMeter test plan. Think of them as a construction toy; each has a specific purpose, and you put them together to create complex load scenarios.
Back to topThe Test Plan Tree
Everything in JMeter lives inside a Test Plan. A tree of test elements is displayed in the left-hand panel of the GUI. The tree’s hierarchy matters because test elements are both hierarchical and ordered. All elements are executed mostly upside-down in the order they appear in the test plan. When it comes to hierarchy, for example, if you have an Assertion at the same level as several Samplers, it will be applied to all Samplers and executed after each of them. If you have an Assertion added as a child of a particular Sampler, it will be executed after that Sampler only. The behavior is described in detail in the Scoping Rules chapter of the JMeter User Manual.
Test Plan
├── Thread Group
│ ├── HTTP Request Sampler
│ │ ├── Response Assertion
│ │ └── Regular Expression Extractor
│ ├── Constant Timer
│ └── View Results Tree (Listener)
└── Summary Report (Listener)
Back to top
Element Types at a Glance
| Element | What It Does | Example |
|---|---|---|
| Thread Group | Defines virtual users (threads), ramp-up, iterations and/or test duration | 50 users over 30 s |
| Sampler | Sends requests to the system under test | |
| Logic Controller | Controls execution flow, i.e. run Samplers conditionally or in specific order | If Controller, Loop Controller |
| Timer | Adds think-time / pacing between requests | Constant Timer, Gaussian Random Timer |
| Pre-Processor | Runs before a sampler executes | JSR223 PreProcessor |
| Post-Processor | Runs after a sampler executes | Regular Expression Extractor, JSON Extractor |
| Assertion | Allows adding custom pass/fail criteria to Samplers | Response Assertion, Duration Assertion |
| Listener | Collects and displays Sampler(s) Results(s) | View Results Tree, Aggregate Report |
| Config Element | Provides/enables shared configuration for Samplers | HTTP Header Manager, CSV Data Set Config |
Execution Order
Within a single sampler, JMeter executes elements in this order:
0. Config Elements
1. Pre-Processors
2. Timer (wait)
3. Sampler (send request)
4. Post-Processors
5. Assertions
6. Listeners
Understanding this order is crucial when you use extractors (post-processors) whose values are needed by assertions or subsequent samplers.
Back to topVariables & Properties
JMeter has two mechanisms for storing and sharing data:
| Mechanism | Scope | Syntax | Example |
|---|---|---|---|
| Variable | Thread-local (each thread has its own copy) | ${variableName} | ${username} |
| Property | Global (shared across all threads and thread groups) | ${__P(propertyName)} | ${__P(host)} |
You create variables via User Defined Variables, CSV Data Set Config, or extractors. Properties can be set via the command line (-Jhost=api.example.com) or in .properties files.
Timers: Simulating Think Time
Real users don’t hammer their system non-stop. They need some time to “think” between operations (e.g. read text, type something, take a longer look at the image or video, etc.).
Timers insert pauses between requests so a JMeter virtual user behaves more like a real user:
| Timer | Behaviour |
|---|---|
| Constant Timer | Fixed delay (e.g., 1 000 ms) |
| Uniform Random Timer | Random delay between a base and maximum |
| Gaussian Random Timer | Normal-distribution delay around a mean |
| Constant Throughput Timer | Allows you to slow down JMeter throughput to desired number of requests per minute |
JMeter .jmx Test Script
When you save a test plan, JMeter writes an XML file with the .jmx extension. This file is human-readable (though verbose) and can be version-controlled in Git like any other source file.
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.3">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan"
testname="My Test Plan" enabled="true">
<!-- ... elements ... -->
</TestPlan>
<hashTree>
<!-- Thread Groups, Samplers, etc. -->
</hashTree>
</hashTree>
</jmeterTestPlan>
Back to topTip: Commit your
.jmxfiles to version control. Because the format is XML, diffs are readable, and you get the full history of test-plan changes.Another Tip: Use JMeter DSL to create and run JMeter tests from Java code.
Summary
- A Test Plan is a tree of test elements; hierarchy defines scope.
- 8 test element types (Sampler, Controller, Timer, Pre/Post-Processor, Assertion, Listener, Configuration Element) cover every testing need.
- JMeter executes elements in a fixed order upside down (or according to Logic Controllers).
- Variables are thread-local; Properties are global for the whole JVM.
- Test plans are stored as
.jmxXML files
Now let’s get familiarized with JMeter Test Plan Fundamentals.