Boost your productivity with Pester snippets

Authoring Pester tests is easy as it is, but if you are lucky enough to own a copy of ISESteroids 2 it now became even easier. Pester version 3.3.1 adds code snippets for you to use.

ISESteroids comes with TAB expansion of code snippets which is really easy to use. Actually this is how easy it is:

Pester_Snippets

You just type a shortcut and press TAB to expand it.

There is also little to memorize. The Describe is dsc, the Context is ctx and the assertions use the first letter of each word for shortcut. The only exception is Should Be NullOrEmpty which is just sbn and not sbnoe.

Here is list of all the snippets available:

Shortcut Command Description
ctx Context Add empty Pester Context block
dsc Describe Add empty Pester Describe block
it It Add empty Pester It block
sb Should Be Add Pester Should Be assertion
sbgt Should Be Greater Than Add Pester Should BeGreaterThan assertion
sblt Should Be Less Than Add Pester Should BeLessThan assertion
sbn Should Be NullOrEmpty Add Pester Should BeNullOrEmpty assertion
sc Should Contain Add Pester Should Contain assertion
se Should Exist Add Pester Should Exist assertion
sm Should Match Add Pester Should Match assertion
st Should Throw Add Pester Should Throw assertion
snb Should Not Be Add Pester Should Be assertion
snbn Should Not BeNullOrEmpty Add Pester Should Not BeNullOrEmpty assertion
snc Should Not Contain Add Pester Should Not Contain assertion
sne Should Not Exist Add Pester Should Not Exist assertion
snm Should Not Match Add Pester Should Not Match assertion
snt Should Not Throw Add Pester Should Not Throw assertion

Installing the snippets

Installing the snippets is easy as well. Update your copy of Pester to the latest version (3.3.1) and import it before importing the latest version of ISESteroids (2.0.13.6).

The easiest way to do that is importing both modules in your ISE profile.

This is how you do that:

Pester_Snippets_02

  • Expand additional menu to access All tools
  • Open the ISE profile
  • Add calls to Import-Module as shown in picture
  • Restart ISE

As noted by Tobias Weltner, author of ISESteroids: Beginning with the current release 2.0.13.6 loading other modules before ISESteroids should not matter anymore. Loading snippets is still done on startup only though, so you have to load Pester first.

About the author: Jakub Jareš

Jakub Jareš is an IT professional with strong background in Windows desktop systems. He started with Powershell a few months ago, and couldn't let go ever since. Showing that with the right attitude, a bit of effort and lot of practice you can become advanced in Powershell in no time.

Related Posts