# How to create new test snippets

**URL:** <https://community.postman.com/t/how-to-create-new-test-snippets/25622>\
**Category:** Help Hub\
**Created:** [July 9, 2021, 6:58am UTC](https://community.postman.com/t/how-to-create-new-test-snippets/25622 "2021-07-09T06:58:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DLazaridis4HEM](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DLazaridis4HEM](https://community.postman.com/u/DLazaridis4HEM)\
**Post date:** [July 9, 2021, 6:58am UTC](https://community.postman.com/t/how-to-create-new-test-snippets/25622/1 "2021-07-09T06:58:54Z")

</div>

Is there a way to create your own test snippets, so that common tests for requests can be easily added to multiple?

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [July 9, 2021, 12:15pm UTC](https://community.postman.com/t/how-to-create-new-test-snippets/25622/2 "2021-07-09T12:15:12Z")

</div>

Really nice feature it would be nice to have

---

<div class="post-metadata">

**Author:** ![archerZ](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@archerZ](https://community.postman.com/u/archerZ)\
**Post date:** [June 10, 2022, 5:19pm UTC](https://community.postman.com/t/how-to-create-new-test-snippets/25622/3 "2022-06-10T17:19:54Z")

</div>

This really should be a feature. This way testing is consistent and even more importantly the test names are consistent.

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 11, 2022, 5:15pm UTC](https://community.postman.com/t/how-to-create-new-test-snippets/25622/4 "2022-06-11T17:15:35Z")

</div>

Hi @DLazaridis4HEM, @praveendvd, @archerZ

Just spotted this and found it a really interesting question… I had an idea for how this could be done…

So if you create a global variable and set the value to be your pm.test snippet like this;

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/6/663cd9faffbcbc2eefbfa5335b4658dfc6c1dfd1.png)

You could then build a little function that grabs the global variables… which in turn appears to trigger the test runs and output the pass/fail results like so;

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/c/cc61bb4f6e25cabbe6883db8545c4c026b1252b2.png)

(I’m new to JS so there may be a better way to do this… but it seems to work).

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 11, 2022, 5:39pm UTC](https://community.postman.com/t/how-to-create-new-test-snippets/25622/5 "2022-06-11T17:39:53Z")

</div>

you can do the second part even simpler like this;

![image](https://us1.discourse-cdn.com/getpostman/original/2X/8/81493a1ab1f9437cb8a2f90091eb35676a1b43d3.png)

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [June 11, 2022, 9:43pm UTC](https://community.postman.com/t/how-to-create-new-test-snippets/25622/6 "2022-06-11T21:43:42Z")

</div>

Yes we could do the second one , but first one is just replacing the test name with the variable value , it’s not actually executing anything .❣🎉🎉

But having test snippet or any custom snippet would be a really nice

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 11, 2022, 10:48pm UTC](https://community.postman.com/t/how-to-create-new-test-snippets/25622/7 "2022-06-11T22:48:55Z")

</div>

> first one is just replacing the test name with the variable value

🤣 yes, now you’ve said it, I can see it! … oops  
(Note to self, don’t try to write code when tired!)
