Code coverage

Last Update: 12/5/2016

api-version = 2.0-preview.1

If you haven't already, look at the information on getting started with these APIs.

Get code coverage data for a build

GET https://{instance}/DefaultCollection/{project}/_apis/test/codeCoverage?api-version={version}[&buildId={int}&flags={int}]
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string Name or ID of the team project.
Query
api-version string Version of the API to use.
buildId int ID of the build for which code coverage data needs to be fetched.
flags enum { Modules, Functions, BlockData } Value of flags determine the level of code coverage details to be fetched.
Flags are additive.

Sample request

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber-TFVC/_apis/test/codeCoverage?buildId=363&flags=7&api-version=2.0-preview

Sample response

Status code: 200
{
  "value": [
    {
      "configuration": {
        "id": 51,
        "flavor": "Debug",
        "platform": "Any CPU",
        "uri": "vstfs:///Build/Build/363",
        "project": {}
      },
      "state": "0",
      "lastError": "",
      "modules": [
        {
          "blockCount": 2,
          "blockData": "Aw==",
          "name": "fabrikamunittests.dll",
          "signature": "c27c5315-b4ec-3748-9751-2a20280c37d5",
          "signatureAge": 1,
          "statistics": {
            "blocksCovered": 2,
            "linesCovered": 4
          },
          "functions": []
        }
      ],
      "codeCoverageFileUrl": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber-TFVC/_api/_build/ItemContent?buildUri=vstfs%3A%2F%2F%2FBuild%2FBuild%2F363&path=%2FBuildCoverage%2FFabrikamUnitTests_20150609.2.Debug.Any%20CPU.51.coverage"
    }
  ],
  "count": 1
}

Get code coverage data for a test run

GET https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/codeCoverage?api-version={version}[&flags={int}]
Parameter Type Notes
URL
instance string VS Team Services account ({account}.visualstudio.com) or TFS server ({server:port}).
project string Name or ID of the team project.
run int ID of the test run for which code coverage data needs to be fetched.
Query
api-version string Version of the API to use.
flags enum { Modules, Functions, BlockData } Value of flags determine the level of code coverage details to be fetched.
Flags are additive.

Sample request

GET https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber-TFVC/_apis/test/runs/51/codeCoverage?flags=7&api-version=2.0-preview

Sample response

Status code: 200
{
  "value": [
    {
      "testRun": {
        "id": "51",
        "name": "buildguest@BUILD-0002 2015-06-09 10:32:28_Any CPU_Debug",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/Fabrikam-Fiber-TFVC/_apis/test/Runs/51"
      },
      "state": "0",
      "lastError": "",
      "modules": [
        {
          "blockCount": 2,
          "blockData": "Aw==",
          "name": "fabrikamunittests.dll",
          "signature": "c27c5315-b4ec-3748-9751-2a20280c37d5",
          "signatureAge": 1,
          "statistics": {
            "blocksCovered": 2,
            "linesCovered": 4
          },
          "functions": []
        }
      ]
    }
  ],
  "count": 1
}