提取TFS 2012构建单元测试结果

时间:2016-10-14 16:01:18

标签: tfs visual-studio-2015 tfs2012

有没有人知道如何快速获得TFS2012中构建的单元测试结果?

目前我必须在visual studio中找到构建并折叠摘要中的各个其他节点,如下面的屏幕截图所示。然后我必须扩展每组结果以解决失败。我只想要一份所有失败测试的清单。

我很乐意使用SQL,SQL Reporting服务甚至是构建中的文本文件。

enter image description here

由于

1 个答案:

答案 0 :(得分:1)

您可以使用TFS API获取测试结果。请查看下面的代码段:

    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://tfsserver:8080/tfs/collectionname"));
    tfs.EnsureAuthenticated();

    IBuildServer tfsBuildServer = tfs.GetService<IBuildServer>();

    IBuildDefinition buildDef = tfsBuildServer.GetBuildDefinition("teamproject", "project");

    var BuildUri = buildDef.LastBuildUri;

    ITestManagementService testManagement = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
    ITestManagementTeamProject testManagementTeamProject = testManagement.GetTeamProject("teamproject");
    IEnumerable<ITestRun> testRuns = testManagementTeamProject.TestRuns.ByBuild(BuildUri);


    foreach (ITestRun testRun in testRuns)
    {
        foreach (ITestCaseResult result in testRun.QueryResults())
        {
            Console.WriteLine(string.Format("TestCaseID:{0}", result.TestCaseTitle.ToString()));
            Console.WriteLine(string.Format("TestCaseOutcome:{0}", result.Outcome.ToString()));
        }
    }