对于我们的新TFS 2015服务器,我想创建一个网页,您可以在其中查看每个构建的警告计数和代码覆盖率的历史记录。如何获取有关单元测试发生了多少警告以及构建的代码数量的信息?我试过通过BuildHttpClient
获取Builds来找到这个但是在通过Build类调试时我没有找到任何具有该信息的属性。以下是我如何获得构建的代码:
public static Build[] GetRunningBuilds(this BuildHttpClient buildServer, string collectionName)
{
return buildServer.GetBuildsAsync(collectionName, statusFilter: BuildStatus.InProgress).Result.ToArray();
}
public static Build[] GetFailedBuilds(this BuildHttpClient buildServer, string collectionName)
{
var builds = buildServer.GetBuildsAsync(collectionName, statusFilter: BuildStatus.Completed, resultFilter: BuildResult.Failed).Result.ToList();
builds.AddRange(buildServer.GetBuildsAsync(collectionName, statusFilter: BuildStatus.Completed, resultFilter: BuildResult.PartiallySucceeded).Result);
return builds.OrderBy(b=>b.FinishTime).ToArray();
}
public static DefinitionReference[] GetBuildDefinitions(this BuildHttpClient buildServer, string collectionName)
{
var buildDefinitions = buildServer.GetDefinitionsAsync(project: collectionName).Result.ToList();
return buildDefinitions.ToArray();
}
答案 0 :(得分:1)
您需要在Microsoft.TeamFoundation.TestManagement.WebApi中使用“GetBuildCodeCoverageAsync”方法来获取代码覆盖率信息。
ITestManagementHttpClient.GetBuildCodeCoverageAsync(string, int, int, object, System.Threading.CancellationToken)
System.Threading.Tasks.Task> GetBuildCodeCoverageAsync(string project,int buildId,int flags, [object userState = null],[System.Threading.CancellationToken cancellationToken = null]) Microsoft.TeamFoundation.TestManagement.WebApi.ITestManagementHttpClient
的成员摘要:将基于REST的消息发送到服务器以获取代码覆盖率 基于buildId和flags的构建对象可以使用此API 在GET过程中。
有关标记信息,请参阅此链接以获取详细信息:Get code coverage data for a build。
答案 1 :(得分:0)
要获得代码覆盖率,您需要使用CoverageAnalysisManager
。
像这样:
TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfs_server_here:8080/tfs/something_here"));
ITestManagementService tcm = (ITestManagementService) tfs.GetService(typeof(ITestManagementService));
ITestManagementTeamProject testManagementTeamProject = tcm.GetTeamProject("team_name_here");
ICoverageAnalysisManager coverageAnalysisManager = testManagementTeamProject.CoverageAnalysisManager;
IBuildCoverage[] queryBuildCoverage = coverageAnalysisManager.QueryBuildCoverage(build.Uri.ToString(), CoverageQueryFlags.Modules);