Skip to content

Instantly share code, notes, and snippets.

@stefanstranger
Last active May 16, 2021 19:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanstranger/839044c5c5c146cb97678933e9a001cc to your computer and use it in GitHub Desktop.
Save stefanstranger/839044c5c5c146cb97678933e9a001cc to your computer and use it in GitHub Desktop.
Run Pester Tests parallel
# Example code of running multiple Pester test in parallel and merging the result into one NUnitReport Test Report file
#region Run Pester Test scripts in parallel
$job = Get-ChildItem -Path "./tests" -Filter "Demo*"
| ForEach-Object -Parallel {
Invoke-Pester -Path $_ -PassThru
} -ThrottleLimit 10 -AsJob
$Results = ($job | Wait-Job | Receive-Job -Keep)
#endregion
#region Create new Pester Object with merged parallel Pester Tests Results.
$Pester = [pester.Run]::new()
$results | ForEach-Object {
$testresult = $_
$pester.Containers += $testresult.Containers
$pester.DiscoveryDuration += $testresult.DiscoveryDuration
$pester.Duration += $testresult.Duration
$pester.Executed += $testresult.Executed
$pester.Failed += $testresult.Failed
$pester.FailedBlocks += $testresult.FailedBlocks
$pester.FailedBlocksCount += $testresult.FailedBlocksCount
$pester.FailedContainers += $testresult.FailedContainers
$pester.FailedContainersCount += $testresult.FailedContainersCount
$pester.FailedCount += $testresult.FailedCount
$pester.FrameworkDuration += $testresult.FrameworkDuration
$pester.NotRun += $testresult.NotRun
$pester.NotRunCount += $testresult.NotRunCount
$pester.Passed += $testresult.Passed
$pester.PassedCount += $testresult.PassedCount
$pester.Result += $testresult.Result
$pester.Skipped += $testresult.Skipped
$pester.SkippedCount += $testresult.SkippedCount
$pester.Tests += $testresult.Tests
$pester.TotalCount += $testresult.TotalCount
$pester.UserDuration += $testresult.UserDuration
}
#endregion
#region Export a Pester result-object to an NUnit-compatible XML-report
$pester | Export-NUnitReport -Path TestResultsFinal.xml
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment