I am trying to add an attachment to a test case In MTM using TFS Api in C#. I am not getting any exception thrown, but still I cant see the uploaded file in 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.
Find the test run, go to Test result, double click the test results to check if there any attachments.