Last active
January 30, 2024 10:38
-
-
Save riosengineer/c51599e7f3de8619829b27f7bc4ada1c to your computer and use it in GitHub Desktop.
Bicep Module Pester Unit Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create Pester container https://pester.dev/docs/commands/New-PesterContainer | |
# Location of the Pester Unit test script location (example) | |
$container = New-PesterContainer -Path './.scripts/bicep-module-tests.ps1' | |
# Set config values and results | |
$config = New-PesterConfiguration | |
$config.TestResult.OutputFormat = "NUnitXML" | |
$config.TestResult.OutputPath = "test-Pester.xml" | |
$config.TestResult.Enabled = $True | |
$config.Run.Container = $container | |
# Invoke Pester run | |
Invoke-Pester -Configuration $config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BeforeDiscovery { | |
# Change the current directory to the Bicep module folder (example) | |
Set-Location -Path "bicep\modules" | |
# Define the module and test paths | |
$testPath = "/home/vsts/work/1/s/bicep/modules/.tests" | |
$moduleFiles = Get-ChildItem -Filter *.bicep | |
$testFiles = foreach ($moduleFile in $moduleFiles) { | |
Join-Path $testPath ($moduleFile.BaseName + '.tests.bicep') | |
} | |
} | |
Describe "test file" -ForEach $testFiles { | |
# Check if a corresponding .tests.bicep file exists for each .bicep module file | |
It "$_ should exist" { | |
$_ | Should -Exist | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment