PowerShell script to extract Passed & Failed Data from a .trx file

Here is the powershell code that would allow you to extract Passed and Failed Data from a .trx file

This would enable to extract the data in a AzureDevops Task

<!-- wp:code -->
<pre class="wp-block-code"><code>
foreach($line in Get-Content $(System.DefaultWorkingDirectory)\TestResults$(Build.BuildId).trx) {
  
  
if($line -match '<Counters total="(?<total>.+)" executed="(?<executed>.+)" passed="(?<passed>.+)" error="(?<error>.+)" failed="(?<failed>.+)" ' )
    {
       $total=$($Matches.total)
       $passed=$($Matches.passed)
       $total+"/"+$passed
        $result=$total+"/"+$passed
         $(result)
Write-Host "##vso[task.setvariable variable=result]$total"
    }

}
</code></pre>
<!-- /wp:code -->

Leave a Reply

Your email address will not be published.

eleven − four =