Skip to content
Latchkey

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 -Force in a pwsh step.
  • Build a New-PesterConfiguration and set Run.Path and Run.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 $config

Gotchas

  • 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

Run this faster and cheaper on Latchkey managed runners. Start free →