# How to create a setup and teardown for running test request in postman/newman?

**URL:** <https://community.postman.com/t/how-to-create-a-setup-and-teardown-for-running-test-request-in-postman-newman/5809>\
**Category:** Help Hub\
**Tags:** newman-project\
**Created:** [June 7, 2019, 10:07am UTC](https://community.postman.com/t/how-to-create-a-setup-and-teardown-for-running-test-request-in-postman-newman/5809 "2019-06-07T10:07:26Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [June 7, 2019, 11:01am UTC](https://community.postman.com/t/how-to-create-a-setup-and-teardown-for-running-test-request-in-postman-newman/5809/2 "2019-06-07T11:01:18Z")

</div>

What do you mean by “I need to cleanup my current testcases”, define “cleanup”. Do you mean clear all persisting environment variables from your last run?

If so, here’s how I’m doing something similar:

Here’s how I’m doing it:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/7/e7daf75a91f4a349442e696f73a5b45044e5806c.png)

Looking at the above image, I have a “Hooks: Before Each” collection folder.  
What I do is, I want all the requests in that folder to run, and then it’ll go to the “[A1] Create” folder.

Once all the requests in “[A1] Create” have run, I use the setNextRequest command to go back to my “Before Each” folder which clears all environment variables so I’ll have no persisting data from previous test runs. (I also have other requests in this before each hook)

Once all the requests in the Before Each folder have run, I use setNextRequest to go to the “[A2] Overdue” folder instead of naturally going to “[A1] Create”

I keep repeating this so before a collection is run, the environment variables get cleared.  
Once the 2nd to last collection has finished running “[A4] Operation: Resolve”, I go to the last collection “[AX] Done” which just clears all environment variables.

I explain this in a bit more detail:

> [@My Code Snippets From The London Postman Summit - Paul Farrell](https://community.postman.com/t/my-code-snippets-from-the-london-postman-summit-paul-farrell/4591):
>
> Hey all, First of all, it was great meeting some of you that attended the Postman event. For those attended, I hope you enjoyed or got something out of my talk slight_smile I’ve been asked to upload the slides I used during my talk but the slides on their own are pretty pointless, as 90% of the content was me talking over images. So I’ll just upload the code examples used in the last third of the slides. For those that didn’t attend or need their memory jogging - this is about using “hooks”…

---

_[View the full topic](https://community.postman.com/t/how-to-create-a-setup-and-teardown-for-running-test-request-in-postman-newman/5809)._
