I made approach to udpdate tescase result in tfs using API after execution of test case , but it makes all other test case status as inprogress in test suite.
It update the outcome of the test case in the test suite , but it also make rest of the test case as in progress which located in the test suite.
ITestCaseResult result = run.QueryResults().FirstOrDefault(r => r.TestCaseId == testCase.Id);
if (result != null)
{
testRun.Title = testCase.Title;
result.ComputerName = Environment.MachineName;
result.Outcome = TestOutcome.Passed;
result.Comment = comments;
result.RunBy = testRun.Owner;
result.State = TestResultState.Completed;
result.Save();
}
I expect,result update should be made on the particular test case id which i am passing at run time and remaining test case status should not change in the test suite.
Without complete code, not sure which part is the root cause, but it maybe related to if (result != null)
, conditional statements effect the result.
Please try to use below code sample to handle this.
publicstaticvoidUpdateResult()
{
TfsTeamProjectCollectiontfs = newTfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(server));
ITestManagementServicetms = tfs.GetService<ITestManagementService>();
ITestManagementTeamProjectproj = tms.GetTeamProject(project);
ITestPlanPlan = proj.TestPlans.Find(1);
IStaticTestSuitesuite = Plan.RootSuite.SubSuites.Where(s => s.Id == 1339).First() asIStaticTestSuite;
ITestCasetestcase = null;
testcase = suite.Entries.Where(e => e.Title == "login").First().TestCase;
ITestRuntestRun = project.TestRuns.Create();
testRun = Plan.CreateTestRun(false);
ITestPointCollectionpoints = Plan.QueryTestPoints("SELECT * FROM TestPoint WHERE TestCaseId ="+ testcase.Id);
foreach(ITestPointp inpoints)
{
testRun.AddTestPoint(p, Plan.Owner);// null);
//testRun.AddTestPoint(p, null);
}
testRun.State = TestRunState.Completed;
testRun.Save();
ITestCaseResultCollectionresults = testRun.QueryResults();
ITestIterationResultiterationResult;
foreach(ITestCaseResultresult inresults)
{
iterationResult = result.CreateIteration(1);
foreach(ITestSteptestStep inresult.GetTestCase().Actions)
{
ITestStepResultstepResult = iterationResult.CreateStepResult(testStep.Id);
stepResult.Outcome = TestOutcome.Passed;
iterationResult.Actions.Add(stepResult);
}
iterationResult.Outcome = TestOutcome.Passed;
result.Iterations.Add(iterationResult);
result.Outcome = TestOutcome.Passed;
result.State = TestResultState.Completed;
result.Save(true);
}
testRun.Save();
testRun.Refresh();
}
More details take a look at this similar question here: Changing the outcome field of testcases within a test suite in Tfs