0

How can I check if I have any test cases failing within my test plan when executing my pipeline in azure devops?

leafar29
  • 301
  • 2
  • 5
  • 12

1 Answers1

1

How can I check if I have any test cases failing within my test plan when executing my pipeline in azure devops?

In Test Plan, the test case has no outcome state(e.g. fail pass ..). The outcome state is for Test points in Test Plan -> Execute tab.

enter image description here

To check if there are failed test points in Test Plan, you could use PowerShell Task to run the Rest API: Test Point - Get Points and Test Suites - Get Test Suites For Plan.

$token = "PAT"

$url1 = " https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/test/Plans/{TestPlanId}/suites?api-version=5.0"


$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$response1 = Invoke-RestMethod -Uri $url1 -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json


$i = 0 

ForEach ($SuitId in $response1.value.id )

{
   $url="https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/testplan/Plans/{TestPlanName}/Suites/$($SuitId)/TestPoint?api-version=6.0-preview.2"
   $response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
   
    ForEach( $outcome in $response.value.results.outcome ) 
    {
     
  
        echo $outcome

        if($outcome -eq  "failed")
        {   
          $i ++
     
    
        }
    
    }

}

echo $i

if ($i -eq 0)
{
  echo "No error"
}

else

{
  echo "##vso[task.logissue type=warning]the error value is $i"
}

Result: enter image description here

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28