I am running an automated test case through MTM while in the code behind, I am updating the test results with some more fields for the running test run and saving it. Though, am getting an error as final state of MTM test run is "Aborted". I get following error -
Unexpected Error occurred. Aborting run: Test results have been modified by another user or session. You must reload the test run and update the test results again.
Code -
ITestRun testRun = project.TestRuns.Find(testRunID);
ITestCaseResult result = testRun.QueryResults()[0];
result.FailureTypeId = (int)FailureType.NewIssue;
result.ResolutionStateId = 2;
result.Save();
testRun.Save();
testRun.Refresh();
This is not allowed to do so.
If you want to edit the test results, you need to wait the test run finishes and test results have generated already, then you could use the API code to change it.