/// <summary>
        /// Sets the new execution outcome.
        /// </summary>
        /// <param name="currentTestCase">The current test case.</param>
        /// <param name="testPlan">The test plan.</param>
        /// <param name="newExecutionOutcome">The new execution outcome.</param>
        /// <param name="comment">The comment.</param>
        /// <param name="testCaseRuns">The test case runs.</param>
        public static void SetNewExecutionOutcome(this TestCase currentTestCase, ITestPlan testPlan, TestCaseExecutionType newExecutionOutcome, string comment, Dictionary <int, TestCaseRun> testCaseRuns)
        {
            if (currentTestCase.ITestCase.Owner == null)
            {
                return;
            }
            var testPoints = testPlan.QueryTestPoints(string.Format("SELECT * FROM TestPoint WHERE TestCaseId = {0} ", currentTestCase.Id));
            var testRun    = testPlan.CreateTestRun(false);

            currentTestCase.IsRunning = string.Empty;
            DateTime startedDate     = DateTime.Now;
            DateTime lastStartedDate = DateTime.Now;

            DateTime endDate = DateTime.Now;
            TimeSpan durationBeforePauses = new TimeSpan();

            if (testCaseRuns.ContainsKey(currentTestCase.Id))
            {
                lastStartedDate      = testCaseRuns[currentTestCase.Id].LastStartedTime;
                startedDate          = testCaseRuns[currentTestCase.Id].StartTime;
                durationBeforePauses = testCaseRuns[currentTestCase.Id].Duration;
                testCaseRuns.Remove(currentTestCase.Id);
            }
            testRun.DateStarted = startedDate;
            testRun.AddTestPoint(testPoints.Last(), ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity);
            TimeSpan totalDuration = new TimeSpan((DateTime.Now - lastStartedDate).Ticks + durationBeforePauses.Ticks);

            testRun.DateCompleted = endDate;
            testRun.Save();

            var result = testRun.QueryResults()[0];

            result.Owner         = ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity;
            result.RunBy         = ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity;
            result.State         = TestResultState.Completed;
            result.DateStarted   = startedDate;
            result.Duration      = totalDuration;
            result.DateCompleted = endDate;
            result.Comment       = comment;
            switch (newExecutionOutcome)
            {
            case TestCaseExecutionType.Active:
                result.Outcome  = TestOutcome.None;
                result.Duration = new TimeSpan();
                break;

            case TestCaseExecutionType.Passed:
                result.Outcome = TestOutcome.Passed;
                break;

            case TestCaseExecutionType.Failed:
                result.Outcome = TestOutcome.Failed;
                break;

            case TestCaseExecutionType.Blocked:
                result.Outcome = TestOutcome.Blocked;
                break;
            }
            result.Save();
        }
Beispiel #2
0
        private static ITestRun CreateRun(ITestManagementTeamProject project, ITestPlan plan, IList <ITestPoint> points, string title)
        {
            ITestRun run = plan.CreateTestRun(false);

            foreach (ITestPoint tp in points)
            {
                run.AddTestPoint(tp, null);
                run.Title = title;
            }
            run.Save();
            return(run);
        }
Beispiel #3
0
        // Mark result in MTM
        private void MarkResultMethod()
        {
            TfsTeamProjectCollection   teamCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://mseng.visualstudio.com:443/defaultcollection"));
            ITestManagementTeamProject project        = teamCollection.GetService <ITestManagementService>().GetTeamProject("VSOnline");
            var service = teamCollection.GetService <ITestManagementService>();

            ITestPlan plan = project.TestPlans.Find(Convert.ToInt32(txtProjectID.Text));

            // Create a new test run
            ITestRun testRun = plan.CreateTestRun(true);


            // Add the certain a test to  the run
            string query = string.Format("SELECT * from TestPoint where SuiteID='{0}'", txtSuitID.Text);

            ITestPointCollection testPoints    = plan.QueryTestPoints(query);
            List <string>        failedCaceMTM = new List <string>();

            foreach (ITestPoint testPoint in testPoints)
            {
                // for caseId please type: testPoint.TestCaseId
                testRun.AddTestPoint(testPoint, null);
                //string caseName = testPoint.TestCaseWorkItem.Implementation.DisplayText;
                //string cname = caseName.Substring(caseName.LastIndexOf(".") + 1);

                //if (GetFailedCaseNamesListFromTrxFile.Contains(cname))
                //{
                //    failedCaceMTM.Add(cname);
                //}
            }
            var blockCase = GetFailedCaseNamesListFromTrxFile.Except(failedCaceMTM).ToList();

            testRun.Save();

            //Update the outcome of the test
            ITestCaseResultCollection results = testRun.QueryResults();

            ;

            foreach (ITestCaseResult result in results)
            {
                // Get case name in MTM.
                string caseName = result.Implementation.DisplayText;
                string name     = caseName.Substring(caseName.LastIndexOf(".") + 1);
                result.Outcome = GetFailedCaseNamesListFromTrxFile.Contains(name) ? TestOutcome.Passed : TestOutcome.Failed;
                result.State   = TestResultState.Completed;
                result.Save();
            }
            testRun.Save();
            testRun.Refresh();
            File.Delete(xmlPath);
        }
Beispiel #4
0
 //create test run
 private static ITestRun CreateTestRun(ITestManagementTeamProject project, ITestPlan plan, ITestPoint tp)
 {
     try
     {
         ITestRun run = plan.CreateTestRun(true);
         run.AddTestPoint(tp, null);
         run.Save();
         return(run);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        /// <summary>
        /// Sets the new execution outcome.
        /// </summary>
        /// <param name="currentTestCase">The current test case.</param>
        /// <param name="testPlan">The test plan.</param>
        /// <param name="newExecutionOutcome">The new execution outcome.</param>
        /// <param name="comment">The comment.</param>
        /// <param name="testCaseRuns">The test case runs.</param>
        public static void SetNewExecutionOutcome(this TestCase currentTestCase, ITestPlan testPlan, TestCaseExecutionType newExecutionOutcome, string comment, Dictionary<int, TestCaseRun> testCaseRuns)
        {
            if (currentTestCase.ITestCase.Owner == null)
            {
                return;
            }
            var testPoints = testPlan.QueryTestPoints(string.Format("SELECT * FROM TestPoint WHERE TestCaseId = {0} ", currentTestCase.Id));
            var testRun = testPlan.CreateTestRun(false);
            currentTestCase.IsRunning = string.Empty;
            DateTime startedDate = DateTime.Now;
            DateTime lastStartedDate = DateTime.Now;

            DateTime endDate = DateTime.Now;
            TimeSpan durationBeforePauses = new TimeSpan();
            if (testCaseRuns.ContainsKey(currentTestCase.Id))
            {
                lastStartedDate = testCaseRuns[currentTestCase.Id].LastStartedTime;
                startedDate = testCaseRuns[currentTestCase.Id].StartTime;
                durationBeforePauses = testCaseRuns[currentTestCase.Id].Duration;
                testCaseRuns.Remove(currentTestCase.Id);
            }
            testRun.DateStarted = startedDate;
            testRun.AddTestPoint(testPoints.Last(), ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity);
            TimeSpan totalDuration = new TimeSpan((DateTime.Now - lastStartedDate).Ticks + durationBeforePauses.Ticks);
            testRun.DateCompleted = endDate;
            testRun.Save();

            var result = testRun.QueryResults()[0];
            result.Owner = ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity;
            result.RunBy = ExecutionContext.TestManagementTeamProject.TestManagementService.AuthorizedIdentity;
            result.State = TestResultState.Completed;
            result.DateStarted = startedDate;
            result.Duration = totalDuration;
            result.DateCompleted = endDate;
            result.Comment = comment;
            switch (newExecutionOutcome)
            {
                case TestCaseExecutionType.Active:
                    result.Outcome = TestOutcome.None;
                    result.Duration = new TimeSpan();
                    break;
                case TestCaseExecutionType.Passed:
                    result.Outcome = TestOutcome.Passed;
                    break;
                case TestCaseExecutionType.Failed:
                    result.Outcome = TestOutcome.Failed;
                    break;
                case TestCaseExecutionType.Blocked:
                    result.Outcome = TestOutcome.Blocked;
                    break;
            }
            result.Save();
        }
Beispiel #6
0
 //create test run
 private static ITestRun CreateTestRun(ITestManagementTeamProject project, ITestPlan plan, ITestPoint tp)
 {
     try
     {
         ITestRun run = plan.CreateTestRun(true);
         run.AddTestPoint(tp, null);
         run.Save();
         return run;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #7
0
        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;
            }
        }