How to configure setUp and tearDown thread groups in JMeter

JMeter special thread groups let a test plan prepare state before the measured workload and clean it up after the regular users finish. A setUp Thread Group can seed records, create sessions, or reset fixture data, while a tearDown Thread Group can remove temporary records or release test-only resources.

Both special groups use the normal Thread Group controls, including user count, ramp-up, loop count, and sampler scope. Keep their sampler labels explicit because their samples can still appear in result files, and avoid putting measured business traffic in either special group when the main load profile belongs in a regular Thread Group.

JMeter does not treat teardown as guaranteed cleanup for every stop path. A gracefully stopped test needs the Run tearDown Thread Groups after shutdown of main threads option on the Test Plan, and a forced stop can still skip the tearDown Thread Group.

Steps to configure JMeter setUp and tearDown thread groups:

  1. Open a validation copy of the .jmx test plan in the JMeter GUI.
  2. Select the Test Plan node.
  3. Add the setup group from AddThreads (Users)setUp Thread Group.
  4. Name the setup group for the state it prepares.
    Name: setUp Thread Group - seed checkout fixture
    Number of Threads (users): 1
    Loop Count: 1

    Use enough threads and loops for the setup work only. Do not mirror the main load profile unless the setup action itself needs concurrency.

  5. Add the setup samplers, configuration elements, or scripts under the setUp Thread Group.
    Sampler label: setUp - seed checkout fixture
    Purpose: create or reset data needed by the main workload
  6. Keep the measured user traffic in a regular Thread Group under the same Test Plan.
    Name: Thread Group - run checkout sampler
    Sampler label: main - run checkout sampler

    The regular Thread Group is the workload whose timing, errors, and throughput normally matter for the load test.

  7. Add the cleanup group from Test PlanAddThreads (Users)tearDown Thread Group.
  8. Name the cleanup group for the state it removes.
    Name: tearDown Thread Group - remove checkout fixture
    Number of Threads (users): 1
    Loop Count: 1
  9. Add the cleanup samplers, configuration elements, or scripts under the tearDown Thread Group.
    Sampler label: tearDown - remove checkout fixture
    Purpose: remove temporary data created for the validation run

    Do not put required production cleanup only in tearDown when operators may use forced stops. Use an external cleanup path for state that must always be removed.

  10. Enable teardown after graceful shutdown when cleanup should run after a normal stop request.
    Test Plan option: Run tearDown Thread Groups after shutdown of main threads

    This option applies to graceful shutdown of the main threads. A forced stop can still bypass teardown.

  11. Add temporary order markers to the validation copy when the application output does not already show setup, main, and teardown activity.
    setUp marker: 01 setUp: seed checkout fixture
    main marker: 02 main: run checkout sampler
    tearDown marker: 03 tearDown: remove checkout fixture

    A temporary JSR223 Sampler can write these lines to a file such as setup-teardown-order.txt during a small validation run. Remove marker-only samplers after the order is proven.

  12. Save the validation copy.
    setup-teardown-thread-groups-configure.jmx
  13. Run a one-user non-GUI validation pass.
    $ jmeter -n -t setup-teardown-thread-groups-configure.jmx -l setup-teardown-results.jtl -j jmeter.log
    Creating summariser <summary>
    Created the tree successfully using setup-teardown-thread-groups-configure.jmx
    Starting standalone test @ 2026 Jun 30 08:21:00 GMT
    Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
    summary +      1 in 00:00:00 =    2.3/s Avg:   425 Min:   425 Max:   425 Err:     0 (0.00%) Active: 1 Started: 1 Finished: 0
    summary +      2 in 00:00:00 =   40.8/s Avg:    12 Min:    11 Max:    14 Err:     0 (0.00%) Active: 0 Started: 1 Finished: 1
    summary =      3 in 00:00:00 =    6.2/s Avg:   150 Min:    11 Max:   425 Err:     0 (0.00%)
    Tidying up ...
    ... end of run

    A three-sample validation run matches one setup sample, one main sample, and one teardown sample. Use a larger smoke run only when the setup or cleanup action needs more than one iteration.
    Related: How to run a JMeter test from the command line

  14. Check the marker output for setup, main, and teardown order.
    $ cat setup-teardown-order.txt
    01 setUp: seed checkout fixture
    02 main: run checkout sampler
    03 tearDown: remove checkout fixture
  15. Check the result file for the three sample labels.
    $ cat setup-teardown-results.jtl
    timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
    1782807660819,425,setUp - seed checkout fixture,200,OK,setUp Thread Group - seed checkout fixture 1-1,text,true,,23,0,1,1,null,0,0,0
    1782807661263,14,main - run checkout sampler,200,OK,Thread Group - run checkout sampler 1-1,text,true,,20,0,1,1,null,0,0,0
    1782807661279,11,tearDown - remove checkout fixture,200,OK,tearDown Thread Group - remove checkout fixture 1-1,text,true,,24,0,1,1,null,0,0,0
  16. Remove temporary marker-only samplers from the validation copy after the order check passes.