【问题标题】:Unable to upload attachments to testresult using TFS API无法使用 TFS API 将附件上传到 testresult
【发布时间】:2015-08-14 19:02:20
【问题描述】:

我正在尝试使用 TFS API 上传附件 以下是代码 sn -p :

    result.State = TestResultState.Completed;
    result.RunBy = identity;

    var attachment = result.CreateAttachment(logFilePath);
    run.Attachments.Add(attachment);

代码不会抛出任何错误。我还看到 IAttachmentOwner.AttachmentUploadCompleted 事件已引发,表明它已完成。 但是我无法在我的 TFSWebPortal 上看到上传的附件。 我在这里错过了什么吗?

P.S:这里的第一个问题。请随时纠正我。

【问题讨论】:

    标签: tfs tfs-sdk


    【解决方案1】:

    您可以使用以下代码使其工作:

    TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfsservername:8080/tfs/DefaultCollection"));
            ITestManagementTeamProject project = tfs.GetService<ITestManagementService>().GetTeamProject("projectName");
    
            foreach (ITestPlan p in project.TestPlans.Query("Select * From TestPlan"))
            {
                ITestRun testRun = p.CreateTestRun(false);
                var testPoints = p.QueryTestPoints("SELECT * from TestPoint");
                foreach (ITestPoint testPoint in testPoints)
                {
                    testRun.AddTestPoint(testPoint, null);
                }
                testRun.Save();
    
                ITestCaseResultCollection results = testRun.QueryResults();
    
                foreach (ITestCaseResult result in results)
                {
                    result.Attachments.Add(result.CreateAttachment(@"C:\Users\visong\Pictures\000.jpg"));
                    result.Outcome = TestOutcome.Warning;
                    result.State = TestResultState.Completed; 
                    results.Save(true);
                }
    
                testRun.Save();
                testRun.Refresh();
            }
    

    然后,您应该能够在 MTM 中使用的测试结果中找到附件。

    【讨论】:

    • 感谢您的回复。其实已经在MTM上传了,有没有办法在TFS Webaccess中看到呢?
    • @EverLearner,我想不出一种方法来检查 TFS Web 访问中的附件。但是, ITestAttachment.Uri 是否有效?您可以使用 URI 来检索附件的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    • 2021-09-18
    • 1970-01-01
    • 2017-10-10
    • 2013-10-04
    • 1970-01-01
    相关资源
    最近更新 更多