PowerShell Studio: Pester Integration

The v5.6.164 service build introduces Pester integration into PowerShell Studio. For those who are not familiar with the Pester module, it is a testing framework for PowerShell. The module allows you to run unit tests on your scripts and functions. I will not go into detail into the Pester module itself. There are plenty of articles covering Pester (see Related Links below).

 

Run Pester Tests

We added the new Run Pester Test (Ctrl + Shift + F8) command to the ribbon’s Run menu:

Ribbon - Run Pester Test

 

You can also access Run Pester Test by using the document tab context menu:

Run Pester Test - Context Menu

Important: At this time, the Run Pester Test command only supports individual ps1 files. In other words, it doesn’t run a test against a psf file.

 

How does it work?

The Run Pester Test command will invoke the associated Pester test script for the active ps1 script file.

Pester defines a test script with the *.Tests.ps1 extension. For example, if you have a script named:

Add-Numbers.ps1

The associated Pester test file should be:

Add-Numbers.Tests.ps1

The *.Tests.ps1 files contain all of your Pester tests that will be executed when you run the Run Pester Test command:

Pester Tests file

 

Note: PowerShell Studio does not require you to dot source the source file within the *.Tests.ps1 script. It will automatically dot source the original file for you when you use the Run Pester Test command.

 

If there isn’t an associated pester test script, you will get an error message:

Pester Test Not Found

 

When a Pester test script is found, the results are displayed in the Tools Output panel:

Pester Results - Tools Output

 

Pester uses symbols to denote each individual result. Here is a summary of what each symbol means:

[+]  Passed
[-]  Failed
[?]  Pending
[!]  Skipped
[?]  Inconclusive

The test totals are reflected at the bottom of the results:

Test Totals

You can double-click on the Description, Context or Test name to quickly jump to that location within the *.Tests.ps1 script.

Double-click navigation

 

Tip Since the Pester results are displayed in the Tools Output panel, you can take advantage of the Copy HTML functionality:

Results - Copy HTML

 

Future Pester Features

We plan on expanding our Pester support for PowerShell Studio. Your feedback is very important to us. Please let us know what Pester features you would like to us implement next by submitting a feature request here.

 

Related Links

Pester Module 

Pester Project Site

Pester Articles on Info.SAPIEN.com

 

Release Notes

You can view the complete service build log here.

 

Feedback

Please continue providing your feedback. Many of the new features included in the service builds are suggestions from users like you. Submit your suggestions or feature requests on the Wish List and Feature Requests forum or the Feature Requests page.