0

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

4

3 回答 3

2

您可以使用未记录的(旧版?)API:

http://{server}/{collection}/{团队项目}/_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
    }]
}

希望这可以帮助

于 2016-07-01T09:13:41.283 回答
0

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

样品请求

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

于 2016-05-17T13:10:19.360 回答
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();
        }
    }
}
于 2016-05-18T06:18:52.280 回答