如何使用TFS Rest API获得单元测试结果? [英] How to get unit test results using TFS Rest API?

查看:75
本文介绍了如何使用TFS Rest API获得单元测试结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Rest API在TFS中检索构建的单元测试结果?

How to retrieve the unit test results of a build in TFS using Rest API?

内部版本定义使用VNext(Visual Studio 2015 Update 3).

The build definition uses VNext (Visual Studio 2015 Update 3).

var vssConnection = new VssConnection(_configurationSpec.TeamProjectCollection, 
    new VssClientCredentials());
_buildClient = vssConnection.GetClient<BuildHttpClient>();

推荐答案

构建的测试结果存储在测试运行中,因此您需要先获取构建的测试运行,然后从测试中检索测试结果跑.以下是代码示例:

The test result of the build is stored in test runs, so you need to get the test run of the build first and then retrieve the test result from the test run. Following is the code sample:

class Program
{
    static void Main(string[] args)
    {
        string ur = "https://xxxxxxx/";
        TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(ur));
        //Get build information
        BuildHttpClient bhc = ttpc.GetClient<BuildHttpClient>();
        string projectname = "Project";
        int buildId = 1;
        Build bui = bhc.GetBuildAsync(projectname,buildId).Result;
        //Get test run for the build
        TestManagementHttpClient ithc = ttpc.GetClient<TestManagementHttpClient>();

        Console.WriteLine(bui.BuildNumber);

        QueryModel qm = new QueryModel("Select * From TestRun Where BuildNumber Contains '" + bui.BuildNumber + "'");

        List<TestRun> testruns = ithc.GetTestRunsByQueryAsync(qm,projectname).Result;
        foreach (TestRun testrun in testruns)
        {

            List<TestCaseResult> testresults = ithc.GetTestResultsAsync(projectname, testrun.Id).Result;
            foreach (TestCaseResult tcr in testresults)
                {
                    Console.WriteLine(tcr.TestCase.Name);
                    Console.WriteLine(tcr.Outcome);
                }

            Console.ReadLine();
        }
        Console.ReadLine();
    }
}

这篇关于如何使用TFS Rest API获得单元测试结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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