This is a mockup for testing a PowerShell DSC class-based resource
To run this example, do the following.
git clone https://github.com/johlju/PesterTestClassBasedResource
cd PesterTestClassBasedResourceInvoke-Pester .\MyDscResource.Tests.ps1Gives expected successful result.
Executing all tests in .\MyDscResource.Tests.ps1
Executing script .\MyDscResource.Tests.ps1
Describing MyDscResource\Get()
Context When the Get method is called
[+] Should not throw an error 1.13s
Tests completed in 1.13s
Tests Passed: 1, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0
Invoke-Pester .\MyDscResource.Tests.ps1The test throws an error.
Executing all tests in .\MyDscResource.Tests.ps1
Executing script .\MyDscResource.Tests.ps1
Describing MyDscResource\Get()
Context When the Get method is called
[-] Should not throw an error 179ms
Expected: the expression not to throw an exception. Message was {Test-HelperFunction throw an error!}
from V:\Source\_Random\PesterTestClassBasedResource\HelperFunctions.psm1:6 char:5
+ throw 'Test-HelperFunction throw an error!'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at <ScriptBlock>, V:\Source\_Random\PesterTestClassBasedResource\MyDscResource.Tests.ps1: line 17
17: { $databaseMembershipClass.Get() } | Should Not Throw