I'm trying to use the TFS API to update test results from automation run separately. I've tried the suggestions from other questions here (particularly How to create a test run and result using the Team Foundation Server API?) as well as from searches elsewhere. No matter what I try I have the same problem: every time I try to add a test point to a test run, I receive the error -
Microsoft.TeamFoundation.TestManagement.Client.TestManagementInvalidOperationException: This test run cannot be created with the test points.
The test points are retrieved from TFS using WIQL, and I check each test point to ensure that it is correct for the test plan, test suite, and test configuration before I attempt to add it.
I can't save the test run without test points.
Sample code (I've gone through so many attempts that my code is now beyond messy)
public void UpdateTests(TestSuiteRun suiteRun)
{
this.Config = FindConfig(suiteRun.Description);
this.Suite = FindSuite(suiteRun.Name);
this.Plan = Suite.Plan;
this.Points = FindPoints(this.Suite.Id, this.Config.Id);
ITestCaseCollection testCases = Suite.AllTestCases;
this.Run = TeamProject.TestRuns.Create();
ConfigureTestRun(); // failing here
this.Result = CreateRunResults();
this.Iteration = CreateSingleIteration(suiteRun.Description);
{
UpdateResultsForScenario(scen);
}
}
And the method to configure the test run:
private void ConfigureTestRun()
{
this.Run.DateStarted = DateTime.Now;
this.Run.DateCompleted = DateTime.Now;
// find the points that correspond to test cases in the run suite
foreach (ITestPoint point in this.Points)
{
if (point.TestCaseExists && point.Plan.Id == this.Plan.Id && point.ConfigurationId == this.Config.Id)
{
this.Run.AddTestPoint(point, this.CurrentUser); // fails with InvalidOperationException
}
}
this.Run.Save();
}
I'm able to connect to TFS and retrieve all the data I need but adding test points to a new test run is driving me crazy.
What have I done wrong?