public static string UpdateResult(string tcid, string comments, string suiteName, bool usebuildnumber, string result = "Passed", string planBuildNumber = "", float duration = 0) { const string testPointQuery = "Select * from TestPoint where TestCaseId= '[#testcaseid#]'"; const string testPointSuiteQuery = "Select * from TestPoint where TestCaseId= '[#testcaseid#]' and SuiteId = '[#testsuiteid#]'"; //Find all instances of the test case var he = _testPlan.QueryTestPointHierarchy(testPointQuery.Replace("[#testcaseid#]", tcid)); if (he.Children.Count <= 0) { return("Testcase not found"); } //Find the child testsuite where the testcase exists under the given suitename string tsid = GetFinalSuiteId(he, suiteName).ToString(CultureInfo.InvariantCulture); if (tsid.Equals("-1")) { return("Testcase does not belong to suite"); } var pointCollection = _testPlan.QueryTestPoints( testPointSuiteQuery.Replace("[#testcaseid#]", tcid).Replace("[#testsuiteid#]", tsid)); var planRun = _testPlan.CreateTestRun(false); planRun.Title = "Test Run"; if (usebuildnumber) { planRun.BuildNumber = planBuildNumber; } try { planRun.AddTestPoint(pointCollection[0], null); planRun.Save(); ITestCaseResult testResult = planRun.QueryResults()[planRun.QueryResults().Count - 1]; testResult.DateStarted = DateTime.Now; if (result.Equals("In progress", StringComparison.OrdinalIgnoreCase)) { testResult.State = TestResultState.InProgress; testResult.Outcome = TestOutcome.None; } else if (result.Equals("Active", StringComparison.OrdinalIgnoreCase)) { testResult.State = TestResultState.Unspecified; testResult.Outcome = TestOutcome.None; } else { testResult.State = TestResultState.Completed; //TestResult.Outcome = TestOutcome.Passed; testResult.Outcome = (TestOutcome)Enum.Parse(typeof(TestOutcome), result); } testResult.ComputerName = Dns.GetHostName(); testResult.RunBy = planRun.Owner; testResult.Duration = TimeSpan.FromSeconds(duration); testResult.Comment = "Suite:" + suiteName + " " + "Build:" + planBuildNumber + " " + comments; testResult.DateCompleted = DateTime.Now; testResult.Save(); return("Success"); } catch (Exception) { planRun.Delete(); throw; } }