Last active
September 10, 2024 12:33
-
-
Save stefanstranger/839044c5c5c146cb97678933e9a001cc to your computer and use it in GitHub Desktop.
Run Pester Tests parallel
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
# 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
@stefanstranger I appreciate your solution. I would like to ask if you know how to print the $pester object result so that the whole result is displayed together and not separately
Current output:
Expected output: