Skip to content

Instantly share code, notes, and snippets.

@riosengineer
Last active January 30, 2024 10:38
Show Gist options
  • Save riosengineer/c51599e7f3de8619829b27f7bc4ada1c to your computer and use it in GitHub Desktop.
Save riosengineer/c51599e7f3de8619829b27f7bc4ada1c to your computer and use it in GitHub Desktop.
Bicep Module Pester Unit Tests
# 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
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