Running Unit Tests in Parallel with Azure DevOps and a Windows Agent

Andrew Varnon
1 min readJun 14, 2021

--

Microsoft has a good writeup on running unit tests in parallel with Azure DevOps and an Ubuntu build agent at https://docs.microsoft.com/en-us/azure/devops/pipelines/test/parallel-testing-any-test-runner?view=azure-devops. I had the need to do the same but with a Windows build agent. I came up with the following PowerShell script as a port of https://github.com/idubnori/ParallelTestingSample-dotnet-core/blob/master/create_slicing_filter_condition.sh.

$filterProperty="Name"$tests = (dotnet test --no-build --list-tests) | Where-Object { $_.StartsWith("    ") } | ForEach-Object { $_.Trim() } | Get-Unique | Sort-Object$testCount = $tests.Length$totalAgents = $(System.TotalJobsInPhase)$agentNumber = $(System.JobPositionInPhase)Write-Host "Total agents: $totalAgents"Write-Host "Agent number: $agentNumber"Write-Host "Total tests: $testCount"Write-Host "Target tests:"$filter = [String]::Emptyfor($i=$agentNumber; $i -le $testCount; $i = $i+$totalAgents) {$targetTestName=$tests[$i - 1]Write-Host "$targetTestName"$filter = $filter + "|$filterProperty=$targetTestName"}$filter = $filter.TrimStart('|')Write-Host "##vso[task.setvariable variable=targetTestsFilter]$filter";

--

--

Andrew Varnon
Andrew Varnon

Written by Andrew Varnon

I am a full stack developer and architect, specializing in .Net and Azure.

Responses (1)