How to Run Pester Tests on Windows in GitHub Actions
Install the Pester module, run Invoke-Pester with a configuration, and exit nonzero so failures fail the step.
Install or update Pester, then call Invoke-Pester with a configuration that sets Run.Exit = $true so a test failure returns a nonzero exit code and fails the job.
Steps
- Install Pester with
Install-Module Pester -Forcein apwshstep. - Build a
New-PesterConfigurationand setRun.PathandRun.Exit = $true. - Call
Invoke-Pester -Configuration $config.
Workflow
.github/workflows/ci.yml
jobs:
test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Run Pester
shell: pwsh
run: |
Install-Module Pester -Force -SkipPublisherCheck
$config = New-PesterConfiguration
$config.Run.Path = './tests'
$config.Run.Exit = $true
$config.TestResult.Enabled = $true
Invoke-Pester -Configuration $configGotchas
- Set
Run.Exit = $true(or check$LASTEXITCODE); otherwise failing tests may not fail the step. - Pin a Pester version when behavior matters, since v4 and v5 syntax differ significantly.
Related guides
How to Run a PowerShell Script Step on Windows in GitHub ActionsRun inline PowerShell or a .ps1 file on a windows-latest runner in GitHub Actions using shell: pwsh, passing…
How to Build a .NET App on Windows in GitHub ActionsBuild and test a .NET application on a windows-latest runner in GitHub Actions with actions/setup-dotnet, dot…