Home > Back-end >  How to get pass pecentage of tests through Rest API in azure devops
How to get pass pecentage of tests through Rest API in azure devops

Time:09-22

How to extract the pass percentage summary of builds and release deployments through Rest API? as I would want to compare the results with a threshold and send mails accordingly to the manager for approving to move to next stage deployment.

enter image description here

CodePudding user response:

You can try to leverage the List action of the Test Runs API.

A call to the List action for a certain test run (runId parameter in the URL) returns an array of TestCaseResult objects. Its outcome property contains the result of a test case. According to the docs:

Valid values = (Unspecified, None, Passed, Failed, Inconclusive, Timeout, Aborted, Blocked, NotExecuted, Warning, Error, NotApplicable, Paused, InProgress, NotImpacted)

So, you can approach your task in the following way:

  1. Run the List action for a test run you're interested in
  2. Parse the response and calculate the number of results where outcome property equals Passed
  3. Divide that number to the total number of objects in the response array to find out the percentage

NOTE: if there are a lot of tests in the run, you'll have to repeat point #1 with paging URL parameters (top and skip) to pull all the results.

  • Related