JMeter – tearDown Thread Group

JMeter - tearDown Thread Group Logo

tearDown Thread Group is a special type of JMeter Thread Group that can be utilized to perform Post-Test actions. The behaviour of tearDown Thread Group is as same as normal 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 check-box ‘Run tearDown Thread Groups after the shutdown of main threads’ from 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 request after completion of the test
  • It is used to clear/delete dataset from a database for 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 following input fields:

  1. Name: To provide tearDown Thread Group name. It could be a Test Case/Test Scenario name
  2. Comments: To write the comment related to 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 then 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 then the entire test will stop abruptly. Any current samplers 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 ramp-up time of 100 seconds then each thread will be initiated at the interval of 10 seconds and at 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 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 the 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 ‘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 word, 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

Leave a Reply

Your email address will not be published. Required fields are marked *