不幸的是,VSTS 的 REST API 的文档现在已下架,但这应该可以帮助您入门 (pulled from Google's Cache)。
此端点处理与测试和代码覆盖率相关的所有内容。
https://{instance}/DefaultCollection/{project}/_apis/test/codeCoverage?api-version={version}[&buildId={int}&flags={int}]
为以下内容提供值,然后运行此Invoke-RestMethod 以取回数据。
$Instance = 'fabrikam-fiber-inc.visualstudio.com' #your URL here
$ProjectName = #YourProjectNameHere
$buildID = #YourBuildIDHere
$version = '2.0-preview'
Invoke-RestMethod -uri https://$Instance/DefaultCollection/$ProjectName/_apis/test/codeCoverage?api-version=$version
这是您可以返回的示例响应:
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": "..."
}
],
"count": 1
}
看起来 blocksCovered 和 livesCovered 可能是您从 API 中获得的最接近的。如果您需要帮助或遇到困难,请告诉我。最终,docs will be back online at this URL.