Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.
Ronald Rink edited this page Jul 24, 2016 · 12 revisions

biz.dfch.PS.Pester.Assertions

The biz.dch.PS.Pester.Assertions PowerShell module is an add-on to Pester and defines custom assertions you can use in your regular Pester scripts.

For a brief description on how to create custom assertions have a look at Extending Pester for fun and profit.

For a quick introduction and the rationale behind it, have a look at Improving Pester and Exception Assertion.

Usage

You can install this module as any other regular PowerShell module. Pester will automatically load and detect the module, so you can use the assertions as described in the examples and wiki. Have a look at the tests as well to see the assertions in action.

As we at d-fens use this module along with our other PowerShell modules it has some dependencies, such as:

You can easily modify and remove the dependencies if you prefer to have a stand-alone version.

Note

Currently the Pester Not operator will NOT work with the ThrowException assertion as the logic in Pester does not seem to handle a not occurring exception and the Pester defined message templates cannot handle that.

Have a look at the test ThrowExceptionWithoutExceptionShouldSucceedButActuallyFails to see such a scenario.

In general you should avoid testing for a not occurring exception. You should better use Should Not Throw or use a custom try/catch block if you have to check for a specific exception that should NOT have been thrown.

Also have a look at this Pester discussion for more information.

Assertions

Clone this wiki locally