コード例 #1
0
        /// <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();
        }
コード例 #2
0
        internal int GetNumberOfAutomatedTests(ITestPlan plan, string state)
        {
            var collection = plan.QueryTestPoints("SELECT * From TestPoint");

            var result = new HashSet <int>();

            foreach (var point in collection)
            {
                if (result.Contains(point.TestCaseId))
                {
                    continue;
                }

                var testCase         = point.TestCaseWorkItem;
                var automationStatus = testCase.CustomFields.TryGetById(10030);
                if (testCase.State != state)
                {
                    continue;
                }

                var isAutomatedTest = automationStatus != null && automationStatus.Value.Equals("Planned");
                if (!isAutomatedTest)
                {
                    continue;
                }

                result.Add(point.TestCaseId);
            }

            return(result.Count);
        }
コード例 #3
0
        public void Initialize(ITestPlan testPlan, ITestManagementTeamProject testProject, string tfsUrl, string project)
        {
            ITestPointCollection testPlanPoints = testPlan.QueryTestPoints("SELECT * FROM TestPoint");

            dataSet = new DataSet();

            foreach (ITestPoint item in testPlanPoints)
            {
                int    priority     = item.TestCaseWorkItem.Priority;
                string testCasePath = string.Format(TestCasePath, item.Plan.Id, item.SuiteId);
                string testCaseUrl  = string.Format(TestCaseUrlBase, tfsUrl, project, testCasePath);
                TestCaseDescription testCaseDescription = new TestCaseDescription(item, testCaseUrl, testCasePath);

                dataSet.AddCasePriority(priority, testCaseDescription);

                if (item.IsTestCaseAutomated)
                {
                    dataSet.Automated.Add(testCaseDescription);
                }

                switch (item.State)
                {
                case TestPointState.InProgress:
                    dataSet.InProgress.Add(testCaseDescription);
                    break;

                case TestPointState.Ready:
                    dataSet.Ready.Add(testCaseDescription);
                    break;

                case TestPointState.Completed:
                    dataSet.Complete.Add(testCaseDescription);
                    break;
                }

                switch (item.AssignedToName)
                {
                case "Unassigned":
                    dataSet.Unassigned.Add(testCaseDescription);
                    break;

                case "Automation User":
                    dataSet.Automated.Add(testCaseDescription);
                    break;

                default:
                    dataSet.Assigned.Add(testCaseDescription);
                    break;
                }
            }

            DatasetChanged();
        }
コード例 #4
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);
        }
コード例 #5
0
        public TestOutcome GetLastTestOutcome(int testPlanId, int suiteId, int testId, int configurationId)
        {
            ITestPlan            plan = TfsShared.Instance.SourceTestProject.TestPlans.Find(testPlanId);
            ITestPointCollection tpc  = plan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + suiteId);
            var testPoints            = tpc.FirstOrDefault(t => t.TestCaseId.Equals(testId) && t.ConfigurationId.Equals(configurationId));

            if (testPoints == null)
            {
                return(TestOutcome.None);
            }

            return(testPoints.MostRecentResultOutcome);
        }
コード例 #6
0
ファイル: TestManager.cs プロジェクト: Thinksys/krypton
 //create test point
 public static ITestPoint CreateTestPoints(ITestPlan testPlan, ITestSuiteBase suite, ITestCase testcase)
 {
     try
     {
         ITestPointCollection tpc = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + suite.Id + " and TestCaseID =" + testcase.Id);
         ITestPoint tp = testPlan.FindTestPoint(tpc[0].Id);
         return tp;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #7
0
 //create test point
 public static ITestPoint CreateTestPoints(ITestPlan testPlan, ITestSuiteBase suite, ITestCase testcase)
 {
     try
     {
         ITestPointCollection tpc = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + suite.Id + " and TestCaseID =" + testcase.Id);
         ITestPoint           tp  = testPlan.FindTestPoint(tpc[0].Id);
         return(tp);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #8
0
        public static IList <ITestPoint> CreateTestPoints(ITestManagementTeamProject project, ITestPlan testPlan, IList <ITestCase> testCases, IList <IdAndName> testConfigs)
        {
            IStaticTestSuite testSuite = CreateTestSuite(project);

            testPlan.RootSuite.Entries.Add(testSuite);
            testPlan.Save();
            testSuite.Entries.AddCases(testCases);
            testPlan.Save();
            testSuite.SetEntryConfigurations(testSuite.Entries, testConfigs);
            testPlan.Save();
            ITestPointCollection tpc = testPlan.QueryTestPoints("SELECT * FROM TestPoint WHERE SuiteId = " + testSuite.Id);

            return(new List <ITestPoint>(tpc));
        }
コード例 #9
0
        /// <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();
        }
コード例 #10
0
 /// <summary>
 /// Gets the test points by test case unique identifier.
 /// </summary>
 /// <param name="testPlan">The test plan.</param>
 /// <param name="testCaseId">The test case unique identifier.</param>
 /// <returns></returns>
 public static ITestPointCollection GetTestPointsByTestCaseId(ITestPlan testPlan, int testCaseId)
 {
     return(testPlan.QueryTestPoints(string.Format(allTestPointsQueryExpression, testCaseId)));
 }
コード例 #11
0
 /// <summary>
 /// Gets the test points by test case unique identifier.
 /// </summary>
 /// <param name="testPlan">The test plan.</param>
 /// <param name="testCaseId">The test case unique identifier.</param>
 /// <returns></returns>
 public static ITestPointCollection GetTestPointsByTestCaseId(ITestPlan testPlan, int testCaseId)
 {
     return testPlan.QueryTestPoints(string.Format(allTestPointsQueryExpression, testCaseId));
 }
コード例 #12
0
        /// <summary>
        /// Quries the MTM Repository for the testcases under the given suiteid and returns all results under it.
        /// </summary>
        /// <param name="suiteId"></param>
        /// <param name="testResults"></param>
        /// <param name="suiteName">List of suiteids</param>
        public static void GetResultDetails(int suiteId, ConcurrentBag <ResultSummary> testResults,
                                            string suiteName)
        {
            Stp.Restart();


            ITestPointCollection pointCollection;

            if (suiteId != -1)
            {
                var suitelist = FindSuiteAndGetAllChildSuites(suiteId);
                suitelist       = suitelist.Substring(0, suitelist.Length - 2);
                pointCollection = _testPlan.QueryTestPoints(TestSuiteQuery.Replace("[#testsuiteid#]", suitelist));
            }
            else
            {
                pointCollection =
                    _testPlan.QueryTestPoints(TestSuiteQuery.Replace("[#testsuiteid#]", suiteName));
            }


            Stp.Stop();
            Initialize = Initialize + (float)Stp.ElapsedMilliseconds / 1000;
            //This loop cannot be made parallel as the mtm methods to retrieve result details are not threadsafe
            foreach (var tpoint in pointCollection)
            {
                ResultSummary res = new ResultSummary();
                Stp.Restart();
                var outcome = tpoint.MostRecentResultOutcome.ToString();

                //Special logic for in-progress status. Though MTM shows the teststatus and outcome in similar way, it stores them separately.
                if (tpoint.MostRecentResult != null && tpoint.MostRecentResult.State.Equals(TestResultState.InProgress))

                {
                    outcome = "In progress";
                }
                if (outcome.Equals("Blocked", StringComparison.OrdinalIgnoreCase))
                {
                    //If a result is unblocked, the most recent result still shows blocked hence we have to have special logic. The alternate option of always using tpoint.MostRecentResult.Outcome
                    //is not feasible as it is slower that tpoint.MostRecentResultOutcome hence should be used only when needed
                    res.Outcome = !tpoint.MostRecentResult.Outcome.ToString()
                                  .Equals("Blocked", StringComparison.OrdinalIgnoreCase) ? "Active" : "Blocked";
                }
                //There is no active status but MTM shows Active in UI
                else if (outcome.Equals("Unspecified", StringComparison.OrdinalIgnoreCase) ||
                         outcome.Equals("None", StringComparison.OrdinalIgnoreCase))
                {
                    res.Outcome = "Active";
                }
                else
                {
                    res.Outcome = outcome;
                }
                Stp.Stop();
                OutcomeTime = OutcomeTime + (float)Stp.ElapsedMilliseconds / 1000;
                Stp.Restart();
                res.SuiteName = SuiteDictionary[tpoint.SuiteId];

                res.TcId = tpoint.TestCaseId;
                Stp.Stop();
                TcidTime = TcidTime + (float)Stp.ElapsedMilliseconds / 1000;

                try
                {
                    Stp.Restart();
                    res.AutomationStatus = tpoint.IsTestCaseAutomated;
                    Stp.Stop();
                    AutomationTime = AutomationTime + (float)Stp.ElapsedMilliseconds / 1000;
                }
                catch (Exception)
                {
                    res.AutomationStatus = false;
                }

                try
                {
                    Stp.Restart();
                    res.Tester = tpoint.AssignedTo != null ? tpoint.AssignedTo.DisplayName : "Nobody";



                    Stp.Stop();
                    TesterTime = TesterTime + (float)Stp.ElapsedMilliseconds / 1000;
                }


                catch (Exception)
                {
                    res.Tester = "Nobody";
                }

                try
                {
                    Stp.Restart();
                    res.Title = tpoint.TestCaseWorkItem.Title;
                    Stp.Stop();
                    TitleTime = TitleTime + (float)Stp.ElapsedMilliseconds / 1000;
                }


                catch (Exception)
                {
                    res.Title = "No Title";
                }
                try
                {
                    Stp.Restart();
                    var tc = tpoint.TestCaseWorkItem;
                    res.Priority = tc.Priority;
                    Stp.Stop();
                    PriorityTime = PriorityTime + (float)Stp.ElapsedMilliseconds / 1000;
                }
                catch (Exception)
                {
                    res.Priority = -1;
                }

                lock (testResults)
                {
                    testResults.Add(res);
                }
            }
        }
コード例 #13
0
        private TestResult calculateTestResultByPlans(ITestManagementTeamProject project, ITestPlan testPlan)
        {
            var testResult = new TestResult();
            testResult.Name = string.Format("{0} - {1}", testPlan.Iteration, testPlan.Name);
            var testSuites = new List<ITestSuiteBase>();
            if (testPlan.RootSuite != null) testSuites.AddRange(GetTestSuiteRecursive(testPlan.RootSuite));

            foreach (var testSuite in testSuites)
            {

                string queryForTestPointsForSpecificTestSuite = string.Format(CultureInfo.InvariantCulture, "SELECT * FROM TestPoint WHERE SuiteId = {0}", testSuite.Id);
                var testPoints = testPlan.QueryTestPoints(queryForTestPointsForSpecificTestSuite);

                foreach (var point in testPoints)
                {
                    // only get the last result for the current test point
                    // otherwise we would mix test results with different users
                    var result = project
                        .TestResults
                        .ByTestId(point.TestCaseId)
                        .LastOrDefault(testResultToFind => testResultToFind.TestPointId == point.Id);
                    updateTestResultWithOutcome(testResult, result);
                }
            }
            return testResult;
        }