Does anyone know how to programatically (using the TFS API) determine what binaries were set to be instrumented as part of a build on TFS?
For example, after running a build on TFS with code coverage it shows this in the output:
...
-> 2 binaries instrumented - 62% of all code blocks covered
SomeAssembly.dll - 392 blocks covered, 368 blocks not covered
SomeExe.exe - 584 blocks covered, 241 blocks not covered
...
I would like to programatically determine that "SomeAssembly.dll" and "SomeExe.exe" are the binaries that were instrumented as part of that build.
I have gotten as far as retrieving the Team Project via the TFS API but am not sure that gets me where I want to go:
TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(versionControlURIRoot + defaultProjectDirectory))
var testManagementService = collection.GetService<ITestManagementService>();
ITestManagementTeamProject teamProject = testManagementService.GetTeamProject(projectName);
Here is the solution:
Get the Team Project:
TfsTeamProjectCollection collection = new TfsTeamProjectCollection(new Uri(versionControlURIRoot + defaultProjectDirectory));
var testManagementService = collection.GetService<ITestManagementService>();
ITestManagementTeamProject teamProject = testManagementService.GetTeamProject(projectName);
Extract the assembly names from the Build Coverage metadata:
List<string> assemblyNames = new List<string>();
if (teamProject != null) {
ICoverageAnalysisManager coverageAnalysisManager = teamProject.CoverageAnalysisManager;
if (coverageAnalysisManager != null) {
IBuildCoverage[] buildCoverage = coverageAnalysisManager.QueryBuildCoverage(buildURI, CoverageQueryFlags.Modules);
List<string> assemblyNames = new List<string>();
foreach (IBuildCoverage buildCoverageDetails in buildCoverage) {
foreach (IModuleCoverage module in buildCoverageDetails.Modules) {
assemblyNames.Add(module.Name);
}
}
}
}