从TFS-SDK查询失败的单元测试? [英] Querying failed unit tests from TFS-SDK?

查看:77
本文介绍了从TFS-SDK查询失败的单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出具有PartialSuccess.StatusFailed.TestStatus的TFS构建详细信息(IBuildDetail),我应该如何检索在该构建中失败的测试列表(MSTest)? >

我有一个可运行的沙箱,可以在其中通过SDK与TFS联系并检索最新的PartialSuccess版本,但似乎找不到哪个服务可能具有此单元测试数据以及如何进行查询.

谁能给我一些启示?

解决方案

这篇文章是很棒的资源,实际上,这是我在搜索类似内容时发现的唯一可用资源.
通常,您需要访问ITestManagementService.
鉴于您已经连接到teamProjectCollection,并且buildDetail,类似这样的东西应该对您有用:

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".

Given a TFS build detail (IBuildDetail) with .Status of PartialSuccess, and .TestStatus of Failed how might I go about retrieving the list of tests (MSTest) that have failed on that build?

I have a working sandbox in which I can contact TFS via the SDK and retrieve the latest PartialSuccess build, but can't seem to find which service might have this unit test data and how I might go about querying it.

Can anyone shed some light?

解决方案

This article is a great resource, actually it was the only one I had found available when I was searching something similar.
In general you need access to ITestManagementService.
Given you already have connection to a teamProjectCollection and a buildDetail, something like this should work out for you :

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);                  
    }
}

(This code is basically a copy from the article above, it is work by Anuj Chaudhary)

Remember to add "Microsoft.TeamFoundation.TestManagement.Client" in your ref list.

这篇关于从TFS-SDK查询失败的单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆