JMeter – tearDown Thread Group

tearDown Thread Group is a special type of JMeter Thread Group that can be utilized to perform Post-Test actions. The behaviour of the tearDown Thread Group is similar to the regular Thread Group element. The only difference is that tearDown Thread Group executes after the completion of normal Thread Group execution.

Similarly, setUp Thread Group helps to perform Pre-Test activities.

Important Note: By default, tearDown Thread Group won’t run if the Test is completed as expected. If you want to run it anyway, mark the checkbox ‘Run tearDown Thread Groups after the shutdown of main threads’ from the Test Plan element.

What is the use of ‘tearDown Thread Group’?

tearDown Thread Group is very much helpful to perform post-test activities like:

  • To delete test users after completion of the test
  • To delete the bulk of data/order/pending requests after completion of the test
  • It is used to clear/delete datasets from a database for the next run

How to add ‘tearDown Thread Group’ in the script?

You can follow the below steps:

  1. Select ‘Test Plan’ node
  2. Right-click on the ‘Test Plan’ node
  3. Hover the mouse on ‘Add’
  4. Hover the mouse on ‘Thread (Users)’
  5. Click ‘tearDown Thread Group’
tearDown Thread Group
Figure 01: tearDown Thread Group

Input fields of the ‘tearDown Thread Group’:

‘tearDown Thread Group’ element has the following input fields:

  1. Name: To provide tearDown Thread Group name. It could be a Test Case/Test Scenario name
  2. Comments: To write a comment related to the tearDown Thread Group
  3. Action to be taken after a Sampler error: Actions taken in case of sampler error occurs, either because the sample itself failed or an assertion failed etc. The possible choices are:
    1. Continue: When an error occurs then ignore the error and continue with the test.
    2. Start Next Thread Loop: When an error occurs then ignore the error, start next loop and continue with the test
    3. Stop Thread: When an error occurs then stop the current thread only which has the error.
    4. Stop Test: When an error occurs, stop the entire test when the current sampler of other threads completed the execution.
    5. Stop Test Now: When an error occurs in any thread, the entire test will stop abruptly. Any current sampler execution may interrupt.
  4. Number of Threads (Users): Number of users to simulate during the performance test.
  5. Ramp-up Period (seconds): How long JMeter should take to get all the threads started? If there are 10 threads and a ramp-up time of 100 seconds then each thread will be initiated at the interval of 10 seconds and at the 100th second all the threads get started.
    Note: This is not the time between two threads to start up.
  6. Loop CountNumber of times to iterate the test case. Alternatively, you can checkmark ‘Infinite’ to stop the test when the specified duration is over or stop the test manually.
  7. Same user on each iteration: On selecting the checkbox ‘Same user on each iteration’, when JMeter gets the cookie in the first response then it saves the cookie and uses it in the following requests; provided that you have added HTTP Cookie Manager.
  8. Specify Thread lifetime: Checkmark the box if you want to run the test for a particular duration or schedule a test. To get more information on scheduling a test in JMeter, refer to the article How to schedule JMeter test?
  9. Duration (seconds): This denotes the total duration of the test. Once you select the ‘Infinite’ option for ‘Loop Count’ then you need to provide the duration of the test to control the test execution.
  10. Startup delay (seconds): If you provide value for ‘Startup delay’ then JMeter adds the specified delay to start the test after pressing the ‘Run’ button. In Non-GUI mode, after hitting the test execution command, JMeter does not fire any request until the specified delay period is over. In simple words, the test starts at a time (=current system time + startup delay)

Possible Parent Element:

  1. Test Plan

Possible Child Element(s):

  1. Sampler
  2. Config Element
  3. Logic Controller
  4. PreProcessor
  5. PostProcessor
  6. Assertion
  7. Timer
  8. Listener
  9. Test Fragment

Following Element(s) can not be added as a child element:

  1. Non-Test Element
  2. Test Plan
  3. Another Thread Group

You may be interested:

Leave a Comment