加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在VSTS构建期间以编程方式将附件添加到测试结果中?

发布时间:2020-12-15 22:48:55 所属栏目:百科 来源:网络整理
导读:我正在寻找一种方法来将我自己的附件添加到测试结果中,以便在构建完成后我可以看到它们…. 我想在编译期间以及测试失败后以编程方式添加这些内容.附件将是截图. 这可能吗? 我快速浏览了一下API参考,但这看起来与关注添加现有测试’运行’的附件,或者在构建
我正在寻找一种方法来将我自己的附件添加到测试结果中,以便在构建完成后我可以看到它们….

enter image description here

我想在编译期间以及测试失败后以编程方式添加这些内容.附件将是截图.

这可能吗?

我快速浏览了一下API参考,但这看起来与关注添加现有测试’运行’的附件,或者在构建方面是创建构建定义并触发它们.我可能错过了它,但我无法找到如何在测试任务完成期间或之后立即添加代码中的附件.

谢谢,

解决方法

You could get test run of the build first and then retrieve the test result from the test run:

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 = x;
        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.Id);
                    Console.WriteLine(tcr.Outcome);
                }

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

一旦获得测试结果ID失败,您可以使用Rest API to attach a file to test result:

POST https://{instance}/DefaultCollection/{project}/_apis/test/runs/{run}/results/{result}/attachments?api-version={version}
Content-Type: application/json
{
  "stream": { string },"fileName": { string },"comment": { string },"attachmentType": { string }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读