Load tests often need data that must exist before users begin and disappear after they finish. In Apache JMeter, a setUp Thread Group prepares that state before regular thread groups run, and a tearDown Thread Group removes it afterward.
Both special groups use the normal user count, ramp-up, and loop controls. Their samples also appear in listeners and result files, so separate request names keep preparation and cleanup from being confused with measured traffic.
Teardown runs when the regular groups finish normally, but it is not guaranteed cleanup. Graceful shutdown needs a Test Plan option, and a forced stop can bypass teardown altogether.
The starting plan needs a regular Thread Group with an HTTP Request. The HTTP fields below belong to a demonstration application with create, read, and remove operations; these are not built-in JMeter endpoints. A real application needs its own equivalent operations.
Creation and cleanup requests change application data. Only a test environment and disposable records belong in this trial; a cleanup endpoint pointed at production could delete real data.
Steps to configure JMeter setUp and tearDown thread groups:
- Set the regular Thread Group to one user, a one-second ramp-up, and one loop for the trial run.

- Configure the regular group's HTTP Request to read the test record.
Name: Read test record Protocol: http Server Name or IP: 127.0.0.1 Port Number: 8080 Method: GET Path: /fixture/status
The demonstration application's response lists the records currently present. In an existing plan, the main request is the operation that needs the prepared data.
- Add a setUp Thread Group from the Test Plan right-click menu under Add → Threads (Users).

- Set the setUp Thread Group to one user, a one-second ramp-up, and one loop.
These are the initial values for a new group. A single setup user avoids creating the same shared record once per load-test user.
- Add an HTTP Request under the setUp Thread Group through its right-click menu under Add → Sampler.

- Configure the setup request to create the disposable record.
Name: Create test record Protocol: http Server Name or IP: 127.0.0.1 Port Number: 8080 Method: POST Path: /fixture/seed Parameters row: Name = name; Value = demo-record
The Add button beneath the Parameters table creates the row. The request sends name=demo-record as a form parameter.
- Add a tearDown Thread Group from the Test Plan right-click menu under Add → Threads (Users).

- Set the tearDown Thread Group to one user, a one-second ramp-up, and one loop.

- Add an HTTP Request under the tearDown Thread Group through its right-click menu under Add → Sampler.

- Configure the teardown request to remove the same disposable record.
Name: Remove test record Protocol: http Server Name or IP: 127.0.0.1 Port Number: 8080 Method: POST Path: /fixture/reset Parameters row: Name = name; Value = demo-record
The cleanup operation targets the same demo-record used by the setup request.
- Enable Run tearDown Thread Groups after shutdown of main threads on the Test Plan.
This option covers Run → Shutdown, which lets the current samplers finish. Forced stopping with Run → Stop can bypass teardown; data that must always be removed needs a separate recovery method.
- Add View Results Tree from the Test Plan right-click menu under Add → Listener.
A listener under the Test Plan receives samples from all three groups. The View Results Tree listener suits this small trial; full load runs belong in non-GUI mode.
Related: How to run a JMeter test from the command line - Choose File → Save Test Plan as to keep the original plan separate.

- Save the copy as setup-teardown.jmx.

- Start the trial with Run → Start.

- Confirm that View Results Tree lists three successful samples in setup, main, then teardown order.
The setUp Thread Group runs first even though it appears below the regular group in the plan tree. A red sample indicates a request failure that needs correction before a load run.
- Check the main request's Response data → Response Body for the record created during setup.
The Read test record response contains {"records": ["demo-record"]}, showing that the data existed when the regular group ran.
- Check the teardown request's Response Body for confirmation that the record was removed.
The Remove test record response contains "present": false. Together with the main response, it shows that preparation happened before use and cleanup happened afterward; the saved plan retains both special groups for later runs.