从 TFS-SDK 查询失败的单元测试?

发布于 2024-12-25 00:55:44 字数 283 浏览 2 评论 0原文

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

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

任何人都可以透露一些信息吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见 2025-01-01 00:55:44

这篇文章是一个很棒的资源,实际上这是我发现的唯一一篇可用的文章我正在搜索类似的内容。
一般来说,您需要访问 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< /a>)

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文