Code Coverage - Get Build Code Coverage

Get code coverage data for a build.

GET https://dev.azure.com/{organization}/{project}/_apis/test/codecoverage?buildId={buildId}&flags={flags}&api-version=7.1-preview.1

URI Parameters

Name In Required Type Description
organization
path True

string

The name of the Azure DevOps organization.

project
path True

string

Project ID or project name

api-version
query True

string

Version of the API to use. This should be set to '7.1-preview.1' to use this version of the api.

buildId
query True

integer

int32

ID of the build for which code coverage data needs to be fetched.

flags
query True

integer

int32

Value of flags determine the level of code coverage details to be fetched. Flags are additive. Expected Values are 1 for Modules, 2 for Functions, 4 for BlockData.

Responses

Name Type Description
200 OK

BuildCoverage[]

successful operation

Security

oauth2

Type: oauth2
Flow: accessCode
Authorization URL: https://app.vssps.visualstudio.com/oauth2/authorize&response_type=Assertion
Token URL: https://app.vssps.visualstudio.com/oauth2/token?client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer

Scopes

Name Description
vso.test Grants the ability to read test plans, cases, results and other test management related artifacts.

Examples

Sample Request

GET https://dev.azure.com/fabrikam/Fabrikam-Fiber-TFVC/_apis/test/codecoverage?buildId=363&flags=7&api-version=7.1-preview.1

Sample Response

{
  "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://dev.azure.com/fabrikam/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
}

Definitions

Name Description
BuildConfiguration

BuildConfiguration Details.

BuildCoverage

Build Coverage Detail

CoverageStatistics
FunctionCoverage
ModuleCoverage
ShallowReference

An abstracted reference to some other resource. This class is used to provide the build data contracts with a uniform way to reference other resources in a way that provides easy traversal through links.

BuildConfiguration

BuildConfiguration Details.

Name Type Description
branchName

string

Branch name for which build is generated.

buildDefinitionId

integer

BuildDefinitionId for build.

buildSystem

string

Build system.

creationDate

string

Build Creation Date.

flavor

string

Build flavor (eg Build/Release).

id

integer

BuildConfiguration Id.

number

string

Build Number.

platform

string

BuildConfiguration Platform.

project

ShallowReference

Project associated with this BuildConfiguration.

repositoryGuid

string

Repository Guid for the Build.

repositoryType

string

Repository Type (eg. TFSGit).

sourceVersion

string

Source Version(/first commit) for the build was triggered.

targetBranchName

string

Target BranchName.

uri

string

Build Uri.

BuildCoverage

Build Coverage Detail

Name Type Description
codeCoverageFileUrl

string

Code Coverage File Url

configuration

BuildConfiguration

Build Configuration

lastError

string

Last Error

modules

ModuleCoverage[]

List of Modules

state

string

State

CoverageStatistics

Name Type Description
blocksCovered

integer

blocksNotCovered

integer

linesCovered

integer

linesNotCovered

integer

linesPartiallyCovered

integer

FunctionCoverage

Name Type Description
class

string

name

string

namespace

string

sourceFile

string

statistics

CoverageStatistics

ModuleCoverage

Name Type Description
blockCount

integer

blockData

string[]

fileUrl

string

Code Coverage File Url

functions

FunctionCoverage[]

name

string

signature

string

signatureAge

integer

statistics

CoverageStatistics

ShallowReference

An abstracted reference to some other resource. This class is used to provide the build data contracts with a uniform way to reference other resources in a way that provides easy traversal through links.

Name Type Description
id

string

ID of the resource

name

string

Name of the linked resource (definition name, controller name, etc.)

url

string

Full http link to the resource