Templates/unit_template.ps1
<#
.Synopsis Template for creating DSC Resource Unit Tests .DESCRIPTION To Use: 1. Copy to \Tests\Unit\ folder and rename MSFT_x<ResourceName>.tests.ps1 2. Customize TODO sections. .NOTES Code in HEADER and FOOTER regions are standard and should not be altered if possible. #> # TODO: Customize these parameters... $Global:DSCModuleName = 'x<ModuleName>' # Example xNetworking $Global:DSCResourceName = 'MSFT_x<ResourceName>' # Example MSFT_xFirewall # /TODO #region HEADER [String] $moduleRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)) if ( (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` (-not (Test-Path -Path (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\')) } else { & git @('-C',(Join-Path -Path $moduleRoot -ChildPath '\DSCResource.Tests\'),'pull') } Import-Module (Join-Path -Path $moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force $TestEnvironment = Initialize-TestEnvironment ` -DSCModuleName $Global:DSCModuleName ` -DSCResourceName $Global:DSCResourceName ` -TestType Unit #endregion # TODO: Other Optional Init Code Goes Here... # Begin Testing try { #region Pester Tests # The InModuleScope command allows you to perform white-box unit testing on the internal # (non-exported) code of a Script Module. InModuleScope $Global:DSCResourceName { #region Pester Test Initialization # TODO: Optopnal Load Mock for use in Pester tests here... #endregion #region Function Get-TargetResource Describe "$($Global:DSCResourceName)\Get-TargetResource" { # TODO: Complete Tests... } #endregion #region Function Test-TargetResource Describe "$($Global:DSCResourceName)\Test-TargetResource" { # TODO: Complete Tests... } #endregion #region Function Set-TargetResource Describe "$($Global:DSCResourceName)\Set-TargetResource" { # TODO: Complete Tests... } #endregion # TODO: Pester Tests for any Helper Cmdlets } #endregion } finally { #region FOOTER Restore-TestEnvironment -TestEnvironment $TestEnvironment #endregion # TODO: Other Optional Cleanup Code Goes Here... } |