-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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.
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.
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.
-
This assertion lets you test for a specific exception by its type or partial type name.
See ThrowException.Tests for examples.
-
PesterThrowDataServiceClientException
This assertion lets you test for a
DataServiceClientException
that may be nested inside anotherException
. Within the exception you can test for a combination ofStatusCode
and/orMessage
(which is parsed as a regex).See ThrowDataServiceClientException.Tests for examples.
-
This assertion lets you test for a specific
FullyQualifiedErrorId
inside anErrorRecord
that may contain a regular expression. Among others it can be used in conjunction withContract-Requires
andContract-Assert
from the biz.dfch.PS.System.Logging module. For more information on 'Code Contracts' for PowerShell see Assert and Exception Logging made easy in PowerShellSee ThrowErrorId.Tests for examples.
-
This assertion lets you test for a specific
CategoryInfo
inside anErrorRecord
that may contain a regular expression. Among others it can be used in conjunction withNew-CustomErrorRecord
from the biz.dfch.PS.System.Utilities module.See ThrowCategory.Tests for examples.
d-fens GmbH, General-Guisan-Strasse 6, CH-6300 Zug, Switzerland, http://d-fens.ch