JMeter Test Plan Example: Four Apache JMeter Scripts to Copy and Adapt

Platform

A JMeter script is a test plan saved as a .jmx file: an XML tree with a Thread Group (the virtual users), samplers such as HTTP Request, config elements, post-processors that pull values out of responses, assertions that check status codes and response text, and timers that add think time. Below are four Apache JMeter test plan examples for performance testing: an HTTP GET with assertions, a login with token correlation, CSV-driven users and a stepped load. Each comes with its element tree, the XML that matters and what to change. We ran every plan with jmeter -n -t in JMeter 5.6.3 against a local test service on 26 November 2026; the results are under each example. The last sections show how to run the same test plan in PFLB Platform, strictly as the PFLB documentation describes it.

Example 1: HTTP Request Sampler with Response Assertions

The simplest useful load test: many virtual users call the home page of a web application or one API endpoint through a single HTTP Request sampler (method GET), and every response is checked. Without assertions, JMeter marks a sample as failed only when the connection fails or the server returns an error status (4xx or 5xx), so an error page served with status 200 counts as a success (Response Assertion in the JMeter component reference).

Test Plan: Example 1: HTTP GET with assertions
└── Thread Group "Users" (5 threads, ramp-up 5 s, 10 loops)
    ├── HTTP Request Defaults (http, ${__P(host,127.0.0.1)}, ${__P(port,18080)})
    └── HTTP Request "GET /api/health" (GET /api/health)
        ├── Response Assertion "Status is 200" (Response Code, Equals, 200)
        ├── Response Assertion "Body says ok" (Text Response, Substring, "status": "ok")
        └── Duration Assertion "Faster than 500 ms" (500)

The first assertion in the JMX file looks like this. Asserion.test_strings is spelled that way in JMeter itself, so do not correct it. Test type 8 means Equals, 16 means Substring and 2 means Contains (a regular expression):

<ResponseAssertion guiclass="AssertionGui" testclass="ResponseAssertion" testname="Status is 200">
  <collectionProp name="Asserion.test_strings">
    <stringProp name="a1">200</stringProp>
  </collectionProp>
  <stringProp name="Assertion.test_field">Assertion.response_code</stringProp>
  <boolProp name="Assertion.assume_success">false</boolProp>
  <intProp name="Assertion.test_type">8</intProp>
</ResponseAssertion>

The thread count and loop count decide how many requests the plan sends: 5 threads and 10 loops give the 50 samples of our run, and the 5-second ramp-up period starts one thread per second.

What to change: the path and method of the HTTP Request sampler; the text in "Body says ok" to a string that only a correct page contains; the 500 ms limit to your response time target; the thread count, ramp-up period and loop count in the Thread Group.

Our run: 50 samples, 0 errors. Then we changed the expected text to "status": "down": every response still came back with status 200, and the assertion failed all 50 samples. That is the check that the body is really tested, not only the status code.

Example 2: Login, Extract the Token and Reuse It (Correlation)

Most applications need a login before the interesting requests. The server returns a session token, and every later request has to send it back. Taking a value from one response and using it in the next request is called correlation. In this test plan example, the login returns JSON with a token field, a JSON Extractor saves it into the variable token, and an HTTP Header Manager under the next request sends Authorization: Bearer ${token}.

Test Plan: Example 2: login, extract token, call API
└── Thread Group "Logged-in users" (3 threads, ramp-up 3 s, 5 loops)
    ├── HTTP Request Defaults
    ├── HTTP Cookie Manager (clear cookies each iteration)
    ├── HTTP Request "POST /api/login" (body: {"username":"alice01","password":"Pa55-alice"})
    │   ├── HTTP Header Manager (Content-Type: application/json)
    │   ├── JSON Extractor "Extract token" ($.token → token, default TOKEN_NOT_FOUND)
    │   └── Response Assertion "Login returns 200"
    └── HTTP Request "GET /api/orders"
        ├── HTTP Header Manager (Authorization: Bearer ${token})
        └── Response Assertion "Orders return 200"

The extractor is the heart of the script:

<JSONPostProcessor guiclass="JSONPostProcessorGui" testclass="JSONPostProcessor" testname="Extract token">
  <stringProp name="JSONPostProcessor.referenceNames">token</stringProp>
  <stringProp name="JSONPostProcessor.jsonPathExprs">$.token</stringProp>
  <stringProp name="JSONPostProcessor.match_numbers">1</stringProp>
  <stringProp name="JSONPostProcessor.defaultValues">TOKEN_NOT_FOUND</stringProp>
</JSONPostProcessor>

The JSON Extractor takes semicolon-separated variable names, JSON paths and default values. Execution order explains why the correlation works: JMeter runs a post-processor right after its sampler and before the assertions, so the variable is ready for the next request (execution order). The default value matters: if the login fails, the next request sends Bearer TOKEN_NOT_FOUND, which is easy to spot in the results, instead of sending an empty header.

What to change: the login path and body; the JSON path to where your application puts the token (for a token in HTML or a header, use a Regular Expression Extractor or a Boundary Extractor instead); the header name if your API does not use Authorization: Bearer. If the session lives in a cookie, the Cookie Manager handles it and you do not need the extractor. Each JMeter thread keeps its own cookies, so each virtual user gets its own session (HTTP Cookie Manager).

Our run: 15 logins and 15 API calls, 0 errors. With a wrong password in the login body, the login got 401, no token was extracted and every API call got 401 too: 30 errors out of 30. That is the check that the token really travels from the first response to the second request.

Example 3: CSV-Driven Test Plan with Different Users

Example 2 logs every thread in as the same user, which servers often cache or lock. To simulate real-world scenarios, give each virtual user its own account and its own data. CSV Data Set Config parameterizes the test plan: it reads one line of a file per iteration and turns the columns into variables. The file users.csv sits next to the test plan:

username,password,productId
alice01,Pa55-alice,1042
bob02,Pa55-bob,2210
carol03,Pa55-carol,3315
Test Plan: Example 3: CSV-driven users
└── Thread Group "CSV users" (3 threads, ramp-up 3 s, 4 loops)
    ├── HTTP Request Defaults
    ├── CSV Data Set Config "users.csv" (names from the header line, all threads share the file)
    ├── HTTP Request "POST /api/login" (body: {"username":"${username}","password":"${password}"})
    │   └── JSON Extractor ($.token → token) and Response Assertion, as in Example 2
    ├── HTTP Request "GET /api/products/${productId}"
    │   └── Response Assertion (Text Response, Substring, "id": "${productId}")
    └── HTTP Request "GET /api/orders" (Authorization: Bearer ${token})
<CSVDataSet guiclass="TestBeanGUI" testclass="CSVDataSet" testname="users.csv">
  <stringProp name="filename">users.csv</stringProp>
  <stringProp name="fileEncoding">UTF-8</stringProp>
  <stringProp name="variableNames"></stringProp>
  <boolProp name="ignoreFirstLine">false</boolProp>
  <stringProp name="delimiter">,</stringProp>
  <boolProp name="quotedData">false</boolProp>
  <boolProp name="recycle">true</boolProp>
  <boolProp name="stopThread">false</boolProp>
  <stringProp name="shareMode">shareMode.all</stringProp>
</CSVDataSet>

An empty variableNames tells JMeter to take the names from the first line of the file (CSV Data Set Config). The assertion on the product request uses the CSV variable too, so it checks that the server answered for the right product, not only that it answered.

What to change: the CSV file with your test accounts and data, with at least as many lines as the test needs (threads multiplied by iterations, if each line should be used once); Recycle on EOF and Stop thread on EOF, if lines must not repeat. Every field and sharing mode of the element is covered on our JMeter CSV Data Set Config page.

Our run: 12 logins, 12 product requests and 12 API calls, 0 errors. The product requests were spread evenly across the file: 4 each for 1042, 2210 and 3315.

Example 4: Stepped Load with Three Thread Groups

A load test that adds users in steps shows where response time starts to grow and throughput stops following the thread count: at the first step, at the second or only at the third. The same layout becomes a stress test if you keep adding steps until errors appear. The standard Thread Group has no step setting, but you can build steps from several Thread Groups that start at different times. Each one uses "Specify Thread lifetime" with a startup delay and a duration, so all of them stop together (Thread Group).

Test Plan: Example 4: stepped load with three Thread Groups
├── HTTP Request Defaults
├── Thread Group "Step 1" (2 threads, ramp-up 2 s, loop forever, startup delay 0 s, duration 30 s)
│   └── HTTP Request "GET /api/health" + Response Assertion + Constant Timer (1000 ms)
├── Thread Group "Step 2" (2 threads, ramp-up 2 s, loop forever, startup delay 10 s, duration 20 s)
│   └── the same request, assertion and timer
└── Thread Group "Step 3" (2 threads, ramp-up 2 s, loop forever, startup delay 20 s, duration 10 s)
    └── the same request, assertion and timer

The XML of the second step shows the fields that make the steps:

<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Step 2: +2 users from 10 s">
  <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
  <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController">
    <stringProp name="LoopController.loops">-1</stringProp>
    <boolProp name="LoopController.continue_forever">false</boolProp>
  </elementProp>
  <stringProp name="ThreadGroup.num_threads">2</stringProp>
  <stringProp name="ThreadGroup.ramp_time">2</stringProp>
  <boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
  <boolProp name="ThreadGroup.scheduler">true</boolProp>
  <stringProp name="ThreadGroup.delay">10</stringProp>
  <stringProp name="ThreadGroup.duration">20</stringProp>
</ThreadGroup>

What to change: the users per step, the step length (the startup delay of each next group) and the total duration; the request, or a Module Controller that points at a Test Fragment, so that all steps run the same user journey without copies. The Constant Timer adds one second of think time; real users pause between actions too, and without a timer each thread sends requests as fast as the server answers. Run the steps against a staging environment first and watch server resources such as CPU and memory while each group starts.

Our run: 111 samples in 29 seconds, 0 errors. Counting threads in five-second buckets of the results file gave 2, 3, 4, 5, 6 and 6 active threads: the three steps with their two-second ramp-ups.

Load Testing with JMeter: How to Run JMeter from the Command Line

Apache JMeter is open source software written in Java (Apache JMeter), and it needs Java 8 or higher (requirements). To start the GUI, run jmeter.bat on Windows or jmeter on Linux and other Unix systems from the bin directory (running JMeter).

To create a plan, right-click the Test Plan and pick Add, Threads (Users), Thread Group. Then right-click the Thread Group to add samplers, config elements and assertions under it, and save the plan as a .jmx file. All four plans above use only components that ship with JMeter, no plugins, and share the same frame, so you can move parts from one to another:

  • HTTP Request Defaults holds the protocol, the Server Name or IP and the port once. The host and port are JMeter properties with defaults, ${__P(host,127.0.0.1)} and ${__P(port,18080)}, so the same file runs against another server with -Jhost= and -Jport= on the command line, without editing the plan.
  • Thread Group sets the number of threads (users), the ramp-up period and the loop count. "Continue" on a sampler error keeps the test running when a request fails, so the errors show up in the results instead of stopping the threads.
  • No listeners. In non-GUI mode, results go to a file with -l results.jtl. A View Results Tree listener is useful while you debug the plan with a few threads in the GUI, because it shows the request details and the response data of every sample; remove it before the load test.

Each example is a full test plan in a .jmx file. If the format itself is new to you, the JMX file glossary entry explains what is inside one.

JMeter also ships its own templates under File, Templates. In JMeter 5.6.3 the list includes Simple HTTP request, Building a Web Test Plan, Building an Advanced Web Test Plan, Recording, Recording with Think Time, JDBC Load Test and Functional Testing Test Plan, among others. They are a good way to see a plan for a protocol you have not used yet (JMeter templates). The Recording template adds an HTTP(S) Test Script Recorder, a proxy that records the requests your browser sends to a web application, if you would rather record a script than build it by hand (recorder). JMeter works at the protocol level and does not execute the JavaScript found in HTML pages (JMeter is not a browser). Each JMeter script example on this page goes one step further than a template: it already has the assertions, correlation, test data or load shape that a real load test needs.

The command we used for each example, with the results written to a file and the JMeter log kept next to it:

jmeter -n -t 02-login-token-correlation.jmx -l results.jtl -j jmeter.log -Jhost=127.0.0.1 -Jport=18080

Use the GUI to build and debug a plan, and execute the load test itself in non-GUI mode: in JMeter load testing, the GUI and its listeners take memory and CPU from the load generator (JMeter: CLI mode; best practices). -n runs JMeter without the GUI, -t names the test plan, -l writes every sample to a test results file and -J sets a property that the plan reads with __P. The summariser prints the sample count, throughput per second, average, minimum and maximum response time and the error percentage while the test runs:

summary =     30 in 00:00:02 =   14.5/s Avg:     2 Min:     0 Max:    21 Err:     0 (0.00%)

To turn the results file into an HTML dashboard for analysis after the run, add -e -o report-folder to the same command (command-line options). Run a new plan with a low thread count first, look at the errors in View Results Tree or the results file, and only then scale it up.

ExampleElements it showsOur run with jmeter -n -t
1. HTTP GET with assertionsHTTP Request Defaults, Response Assertion, Duration Assertion50 samples, 0 errors; 50 of 50 failed with a wrong expected text
2. Login and token correlationJSON Extractor, HTTP Header Manager, HTTP Cookie Manager30 samples, 0 errors; 30 of 30 errors with a wrong password
3. CSV-driven usersCSV Data Set Config, variables in body, path and assertion36 samples, 0 errors
4. Stepped loadThree Thread Groups with startup delay and duration, Constant Timer111 samples, 0 errors; 2 → 4 → 6 threads

Run the Same Test Plan in PFLB

When the plan works on your machine, the next problem is load: one JMeter machine runs out of resources (CPU, memory or network) long before a large performance test ends, and spreading the plan over several machines is its own project. PFLB Platform imports JMeter scripts and runs them as tests. Everything below comes from the PFLB documentation (import from JMX; supported plugins and elements of JMX scripts).

  1. Import the script. Click + New Test, then Import from JMeter, and upload the JMX file (up to 100 MB). Upload the supporting files the script uses as well, such as users.csv from Example 3; the documentation says the paths inside the JMX can stay as they are. Click Upload, and the platform creates a container for the script.
  2. Check what was imported. In the container you review the files, the thread groups and the load profile.
  3. Scale it. You can copy the container with the imported script to generate more load, import different scripts into one test and see them on one Grafana dashboard, and choose a region for each container to simulate geographically distributed load.
  4. Add SLAs. Thresholds can be set for the whole test, a transaction or a single request: average response time, error rate and 95th percentile for all three, plus requests per second for the test and a request, and transactions per second for a transaction.
  5. Check it with a debug run. The Debug run toggle starts a short run; for a standard Thread Group the documentation lists 1 thread, at most 10 iterations and at most 300 seconds.

What the documentation says about the elements used in the four examples:

  • HTTP Request: the platform shows the URL, protocol, parameters, headers and body. HTTP Header Manager and HTTP Request Defaults are applied to that display, with the closer element taking priority, and the JMX does not change.
  • JSON Extractor, Response Assertion, Duration Assertion, CSV Data Set Config and HTTP Cookie Manager are supported, but you cannot edit them in the platform GUI. Change them in JMeter and re-upload the script.
  • Constant Timer is supported in all test types.
  • Thread Group is supported, but its settings cannot be changed in the GUI; you can disable thread groups you do not want in the test. The documentation recommends jp@gc - Ultimate Thread Group for imported scripts, because for it the platform shows the load profile and lets you edit each step: start delay, ramp-up time, duration, number of virtual users and ramp-down time, set in minutes. The steps of Example 4 can be expressed as rows of one Ultimate Thread Group instead of three groups.
  • Listeners are disabled after import. JMeter log files can be downloaded when the test is done.

More on running existing JMeter scripts at scale is on our JMeter load testing on PFLB page. If you start from browser traffic rather than from an empty plan, the HAR to JMX page shows how to turn a recorded HAR file into a test plan.

The documentation lists the JMeter properties the platform supports, such as httpclient4.retrycount or csvdataset.eofstring, but it does not describe passing your own properties, like the host and port these examples read with -J. Before you import one of them, set the default values inside ${__P(host,...)} and ${__P(port,...)} to your test host, and check the plan with a debug run before the full load.

Sign Up

Common Mistakes When You Adapt a JMeter Script Example

  1. No assertions. JMeter marks a response as failed only on a connection error or an error status (4xx or 5xx). An error page with status 200 counts as a success unless an assertion checks the body.
  2. A hard-coded session value. A token or session ID recorded once and pasted into every request works for one user and fails for the rest. Extract it from the login response, as in Example 2.
  3. One account for every thread. Use a CSV file with one account per thread, as in Example 3.
  4. No think time. Without timers, a few threads send far more requests per second than the same number of real users would.
  5. Listeners left on during the load test. View Results Tree keeps every response in memory. Write results to a file in non-GUI mode instead.
  6. Testing someone else's server. Run load only against systems you own or have written permission to test, such as your own staging environment. These examples were run against a local test service.

If you would rather hand the whole job to engineers, PFLB's performance engineers design the load model, prepare the test data, write and maintain the scripts, run the tests and explain the results with your team.

Contact Us

Questions About JMeter Test Plans

What does a JMeter test plan contain?

A Thread Group with the number of virtual users, the ramp-up period and the loop count; samplers such as HTTP Request; config elements such as HTTP Request Defaults, HTTP Cookie Manager and CSV Data Set Config; post-processors that pull values out of responses; assertions that check status codes and response text; and timers that add think time. JMeter saves the plan as an XML file with the .jmx extension.

How do I run a JMeter test plan from the command line?

Run jmeter -n -t plan.jmx -l results.jtl: -n starts JMeter without the GUI, -t names the test plan and -l writes every sample to a results file. Add -Jname=value for a property that the plan reads with ${__P(name,default)}, and -e -o report-folder for an HTML dashboard.

How do I give each virtual user its own login in a JMeter script?

Add a CSV Data Set Config with one line per test account. JMeter reads one line per iteration and turns the columns into variables such as ${username} and ${password}; with an empty Variable Names field, it takes the names from the first line of the file, as in Example 3.

How do I build a stepped load test in JMeter without plugins?

Use several Thread Groups that start at different times. Turn on "Specify Thread lifetime" in each one, give each next group a longer startup delay and set the durations so that all groups stop together, as in Example 4.

Can I run these JMeter examples in PFLB Platform?

Yes, you can import them. Click + New Test, then Import from JMeter, and upload the JMX file (up to 100 MB) with the supporting files it uses, such as users.csv from Example 3. Before you import, set the default host and port inside ${__P(host,...)} and ${__P(port,...)} to your test host, and check the plan with a debug run before the full load.