【问题标题】:Querying failed unit tests from TFS-SDK?从 TFS-SDK 查询失败的单元测试?
【发布时间】:2012-01-04 18:18:13
【问题描述】:

给定一个 TFS 构建详细信息 (IBuildDetail),其中包含 .StatusPartialSuccess.TestStatusFailed,我该如何检索在该构建中失败的测试列表 (MSTest)?

我有一个工作沙箱,我可以在其中通过 SDK 联系 TFS 并检索最新的 PartialSuccess 构建,但似乎无法找到哪个服务可能有这个单元测试数据以及我可以如何去查询它。

谁能解释一下?

【问题讨论】:

    标签: unit-testing mstest tfs-sdk


    【解决方案1】:

    This 文章是一个很好的资源,实际上它是我在搜索类似内容时发现的唯一可用的资源。
    一般而言,您需要访问 ITestManagementService
    假设您已经有连接到teamProjectCollectionbuildDetail,这样的事情应该适合你:

    var tstService = (ITestManagementService)teamProjectCollection.GetService(typeof(ITestManagementService));
    ITestManagementTeamProject testManagementTeamProject = tstService.GetTeamProject(buildDetail.TeamProject);
    
    IEnumerable<ITestRun> testRuns =  testManagementTeamProject.TestRuns.ByBuild(buildDetail.Uri);
    
    foreach (var testRun in testRuns)
    {
        ITestCaseResultCollection testcases = testRun.QueryResultsByOutcome(TestOutcome.Failed);
        foreach (var testcase in testcases)
        {
            Console.WriteLine("TestCase ID: " + testcase.TestCaseId);
            Console.WriteLine("TestCase Title: " + testcase.TestCaseTitle);
            Console.WriteLine("Error Message: " + testcase.ErrorMessage);                  
        }
    }
    

    (这段代码基本上是从上面的文章中复制的,它是Anuj Chaudhary工作的)

    请记住在您的参考列表中添加“Microsoft.TeamFoundation.TestManagement.Client”。

    【讨论】:

    • 不得不添加更多的程序集引用,但这确实是答案。谢谢!
    猜你喜欢
    • 2010-11-28
    • 1970-01-01
    • 2016-06-09
    • 2021-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    相关资源
    最近更新 更多