如何通过TFS Client Libaries for REST API获取测试运行附件列表?

时间:2016-05-16 14:30:44

标签: rest tfs tfs-sdk azure-devops-rest-api

有一个方法TestManagementHttpClient.GetTestRunAttachmentContentAsync(),它需要附件ID和其他参数,但我找不到一个方法来获取附加到测试运行的所有文件的列表,所以我想知道是否有一种方法吗?

3 个答案:

答案 0 :(得分:2)

您可以使用未记录的(遗留?)API:

http:// {server} / {collection} / {Team project} / _ api / _testrun / GetTestRunAttachments?testRunId = {testid}

这会返回一个数组。请注意,此API可能在将来发生变化:

{
    "__wrappedArray": [{
        "__type": "TestRunAttachmentModel:#Microsoft.TeamFoundation.Server.WebAccess.TestManagement",
        "attachmentComment": "",
        "attachmentCreationDate": "\/Date(1467360776123)\/",
        "attachmentId": 1233,
        "attachmentName": "xy 2016-07-01 10_07_03.trx",
        "attachmentSize": 6800374
    },
    {
        "__type": "TestRunAttachmentModel:#Microsoft.TeamFoundation.Server.WebAccess.TestManagement",
        "attachmentComment": "",
        "attachmentCreationDate": "\/Date(1467360782220)\/",
        "attachmentId": 1234,
        "attachmentName": "xy 2016-07-01 10_05_50.coverage",
        "attachmentSize": 7426581
    }]
}

希望这有帮助

答案 1 :(得分:0)

您可以通过Rest API下载测试运行附件。更多详情请参阅Test attachments下载测试运行附件

  

示例请求

     

获取https://fabrikam-fiber-inc.visualstudio.com/defaultcollection/fabrikam/_apis/test/runs/1/attachments/1?api-version=2.0-preview

答案 2 :(得分:0)

目前还没有任何方法可以通过Rest API直接获取所有附件,您可以在VSTS User Voice上提交功能请求。

但是如果您使用.NET Client Libraries,则可以从" ITestRun.Attachments"获取所有附件。请参阅以下代码以供参考:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string pu = "http://yourtfsserverurl";
            string projectname = "projectname";
            int testrunid = 1;//ID of test run
            TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(pu));
            ITestManagementService itms = ttpc.GetService<ITestManagementService>();
            ITestManagementTeamProject itmtp = itms.GetTeamProject(projectname);
            ITestRun itr = itmtp.TestRuns.Find(testrunid);
            foreach (ITestAttachment ita in itr.Attachments)
            {
                Console.WriteLine(ita.Name);
            }
            Console.ReadLine();
        }
    }
}