I have found several samples about retrieving test results using the TFS API, but no documentation on creating results programmatically. My aim is to create a lightweight alternative to using Microsoft Test Manager for running manual tests. Does anyone have experience with this? Are there any examples out there that I'm missing?
Here's what I have so far:
ITestCaseResult CreateNewTestCaseResult(ITestSuiteEntry testCaseEntry)
{
var run = testCaseEntry.TestSuite.Plan.CreateTestRun(false /* not automated */);
run.AddTest(testCaseEntry.TestCase.Id, suiteEntry.TestSuite.DefaultConfigurations[0].Id, suiteEntry.TestSuite.Plan.Owner);
run.Save(); // so that results object is created
return run.QueryResults()[0];
}
I'm not sure if this is the correct way to initate a new run, and I'm not sure how to record results for each action of the test.
Update 15 Aug 2012:
The sample below has now been integrated into my open source TFS Test Steps Editor tool. In the latest version it gained the ability to publish test results to TFS. See the source on GitHub.
I now have working code for publishing test results. Note, the following code accepts ITestPoint (this represents a test case within a particular suite) and has some of my internal classes (not included) that just provide outcome and attachment paths for each step.
Test Action does not appear to have properties for setting pass/fail or to add attachments.
That is done at the parent level (TestCase).
Here is how you correctly initiate a new run:
Reference