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 -->

6 Responses

  1. This is my first time visit at hewre and i am in fact happy
    to read everthing at alone place.

    my page … bully boy vibrator

  1. November 12, 2020

    … [Trackback]

    […] Read More on on that Topic: azuredevopsguide.com/powershell-script-to-extract-passed-failed-data-from-a-trx-file/ […]

  2. November 14, 2020

    … [Trackback]

    […] Read More on that Topic: azuredevopsguide.com/powershell-script-to-extract-passed-failed-data-from-a-trx-file/ […]

  3. November 14, 2020

    … [Trackback]

    […] Read More Information here on that Topic: azuredevopsguide.com/powershell-script-to-extract-passed-failed-data-from-a-trx-file/ […]

  4. November 16, 2020

    … [Trackback]

    […] Read More here on that Topic: azuredevopsguide.com/powershell-script-to-extract-passed-failed-data-from-a-trx-file/ […]

  5. November 24, 2020

    … [Trackback]

    […] Find More on that Topic: azuredevopsguide.com/powershell-script-to-extract-passed-failed-data-from-a-trx-file/ […]

Leave a Reply

Your email address will not be published.

15 + nine =