简体   繁体   English

在MTM中向测试用例添加附件

[英]Adding attachment to test case in MTM

I am trying to add an attachment to a test case In MTM using TFS Api in C#. 我正在尝试在C#中使用TFS Api向MTM中的测试用例添加附件。 I am not getting any exception thrown, but still I cant see the uploaded file in TFS. 我没有抛出任何异常,但是仍然无法在TFS中看到上传的文件。 I am adding the relevant code that I am trying to add the attachment for your reference. 我正在添加尝试添加附件的相关代码,以供您参考。 Please help me out. 请帮帮我。

foreach (ITestCaseResult result in results)
{
   result.Attachments.Add(result.CreateAttachment(@"ThePath"));    
   result.Outcome = TestOutcome.Failed;                    
   result.State = TestResultState.Completed;
   result.Save();
} 
results.Save(true);
testRun.Save();
testRun.Refresh();

The code you posted above is correct. 您上面发布的代码是正确的。 It could add an attachments to your test results. 它可能会在您的测试结果中添加附件。

Pay attention that the code above is not used to add attachments to test run or test case, it's used to add attachments to test results. 请注意,上面的代码不是用于向测试运行或测试用例添加附件,而是用于向测试结果添加附件。 Please make sure you refer to the test result page to check attachments in TFS. 请确保您参考测试结果页面以检查TFS中的附件。

Find the test run, go to Test result , double click the test results to check if there any attachments. 找到测试运行,转到“ 测试结果” ,双击测试结果以检查是否有附件。

在此处输入图片说明

This worked for me:- 这对我有用:

                String path= @"path";
                var store = tfsCollection.GetService<WorkItemStore>();
                Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem wi = store.GetWorkItem(testCaseId);
                wi.Attachments.Add(new Attachment(path));
                wi.Save();                    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM