예제 #1
0
        internal static int Add_TestResults(
            Excel.XlLocation insertAt,
            Options_AZDO_TFS options,
            ITestManagementTeamProject testManagementTeamProject)
        {
            Int64 startTicks = Log.APPLICATION("Enter", Common.LOG_CATEGORY);

            int itemCount = 0;

            string query = String.Format(
                "SELECT *"
                + " FROM TestResult"
                + " WHERE [DateCreated] > '1/1/2021'");

            ITestCaseResultCollection testCaseResults = testManagementTeamProject.TestResults.Query(query);
            int totalItems = testCaseResults.Count;

            int[] associatedWIs = testCaseResults.QueryAssociatedWorkItems();

            XlHlp.DisplayInWatchWindow($"Processing ({ totalItems }) testCaseResults");

            foreach (ITestResult testResult in testCaseResults)
            {
                insertAt.ClearOffsets();

                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), testManagementTeamProject.TeamProjectName);

                // IAttachmentOwner

                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), $"{testResult.Attachments.Count}");

                // ITestResult
                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), $"{testResult.CollectorsEnabled.Count}");
                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), $"{testResult.Comment}");
                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), $"{testResult.DateCreated}");
                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), $"{testResult.DateStarted}");
                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), $"{testResult.DateCompleted}");
                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), $"{testResult.Duration}");
                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), $"{testResult.ErrorMessage}");
                XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), $"{testResult.Outcome}");



                insertAt.IncrementRows();
                itemCount++;

                AZDOHelper.ProcessItemDelay(options);
                AZDOHelper.DisplayLoopUpdates(startTicks, options, totalItems, itemCount);
            }

            Log.APPLICATION("Exit", Common.LOG_CATEGORY, startTicks);

            return(itemCount);
        }
예제 #2
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);
        }
        private ITestCaseResult GetTestCaseResult(ITestCaseResultCollection testRun, ITestCase testCase, ITestPoint testPoint)
        {
            var owner  = _tfsBase.TestManagementService.TfsIdentityStore.FindByTeamFoundationId(testCase.OwnerTeamFoundationId);
            var result = testRun.Single(x => x.TestPointId == testPoint.Id);

            result.Owner         = owner;
            result.RunBy         = owner;
            result.State         = TestResultState.Completed;
            result.DateStarted   = DateTime.Now;
            result.Duration      = new TimeSpan(0L);
            result.DateCompleted = DateTime.Now.AddMinutes(0.0);

            return(result);
        }
예제 #4
0
        public static void FinailizeTestRun()
        {
            var x = 0;

            //Create test result
            RunData.Testrun.Save();

            ITestCaseResultCollection results = RunData.Testrun.QueryResults();

            foreach (ITestCaseResult testresult in results)
            {
                var i = RunData.RunCacheData[x];
                x++;// there is an assumption that we will have one object per test in the run
                testresult.RunBy        = RunData.Testrun.Owner;
                testresult.Outcome      = TranslateTestResult(i.CaseResult);
                testresult.State        = TestResultState.Completed;
                testresult.ErrorMessage = i.ErrorOutput;
                testresult.Comment      = i.Comment;
                testresult.Save();
            }
        }
예제 #5
0
 private static void DeleteTestResults(ITestCaseResultCollection allTestResults, int olderThanDays)
 {
     try
     {
         foreach (ITestCaseResult testResult in allTestResults)
         {
             if ((DateTime.Now - testResult.DateCreated).TotalDays > olderThanDays)
             {
                 try
                 {
                     testResult.GetTestRun().Delete();
                 }
                 catch (Exception e)
                 {
                     Console.WriteLine(e.Message);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(ConsoleMessages.EXCEPTION_WHILE_DELETING_TEST_RUNS + e.Message);
     }
 }
예제 #6
0
 private static void DeleteTestResults(ITestCaseResultCollection allTestResults, int olderThanDays)
 {
     try
     {
         foreach (ITestCaseResult testResult in allTestResults)
         {
             if ((DateTime.Now - testResult.DateCreated).TotalDays > olderThanDays)
             {
                 try
                 {
                     testResult.GetTestRun().Delete();
                 }
                 catch (Exception e)
                 {
                     Console.WriteLine(e.Message);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(ConsoleMessages.EXCEPTION_WHILE_DELETING_TEST_RUNS + e.Message);
     }
 }
예제 #7
0
        /// <summary>
        /// This method is used to initiate execution in test manager, create test run and results and set required parameters
        /// </summary>
        /// <returns></returns>
        public bool InitExecution()
        {
            //Create a connection to tfs project
            ITestManagementTeamProject tfsProject = null;

            tfsProject = GetProject(ProjectUrl, ProjectName);

            if (tfsProject == null)
            {
                throw new Exception("Unabled to connect to test project: " + ProjectName);
            }
            //Retrieve test plan details
            ITestPlanCollection testPlans = tfsProject.TestPlans.Query("select * from TestPlan where PlanName ='" +
                                                                       TestPlanName + "'");

            if (testPlans.Count == 0)
            {
                throw new Exception("Unabled to locate test plan: " + TestPlanName + " in Test Manager.");
            }

            ITestPlan tfsTestPlan = testPlans.First();

            //Retrieve test suite details
            ITestSuiteCollection testSuites = null;

            //Optionally, test suite id of test manager can be passed as an command line arguments
            //This helps when same test case has been added to multiple test suites
            if (TestSuiteId.ToLower().Equals(string.Empty) ||
                TestSuiteId.ToLower().Equals(string.Empty) ||
                TestSuiteId.ToLower().Equals("testsuiteid", StringComparison.OrdinalIgnoreCase))
            {
                testSuites = tfsProject.TestSuites.Query("Select * from TestSuite where Title='" +
                                                         TestSuiteName + "' and PlanID='" + tfsTestPlan.Id + "'");
            }
            else
            {
                testSuites = tfsProject.TestSuites.Query("Select * from TestSuite where Id='" +
                                                         TestSuiteId + "' and PlanID='" + tfsTestPlan.Id + "'");
            }


            IStaticTestSuite tfsTestSuite = testSuites.Cast <IStaticTestSuite>().FirstOrDefault(testSuite => testSuite.Title.ToLower().Equals(TestSuiteName.ToLower()) || testSuite.Id.ToString().Equals(TestSuiteId));

            if (tfsTestSuite == null)
            {
                throw new Exception("Unabled to locate test suite: " + TestSuiteName + " in Test Manager Test Plan: " + TestPlanName);
            }

            //Get handle to a specific test case in the test suite
            ITestCase tfsTestCase = tfsTestSuite.AllTestCases.FirstOrDefault(testcase => testcase.Id.Equals(TestCaseId));

            if (tfsTestCase == null)
            {
                throw new Exception("Unabled to locate test case id: " + TestCaseId + " in Test Manager");
            }

            //Create a test run
            ITestPoint tfsTestPoint = CreateTestPoints(tfsTestPlan, tfsTestSuite, tfsTestCase);
            ITestRun   tfsTestRun   = CreateTestRun(tfsProject, tfsTestPlan, tfsTestPoint);

            tfsTestRun.Refresh();

            //Suprisingly, most recently created test results should be available in last, but test manager returns it at first position
            //Find test results that were create by the test run
            ITestCaseResultCollection tfsTestCaseResults = tfsProject.TestResults.ByTestId(tfsTestCase.Id);
            ITestCaseResult           tfsTestResult      = tfsTestCaseResults.Last(); //Default assignment

            foreach (ITestCaseResult testResult in tfsTestCaseResults)
            {
                if (testResult.DateCreated.CompareTo(tfsTestRun.DateCreated) == 1)
                {
                    tfsTestResult = testResult;
                    break;
                }
            }

            //Set test run and result id to property variable for usage while uploading results
            Property.RcTestRunId    = tfsTestRun.Id;
            Property.RcTestResultId = tfsTestResult.TestResultId;

            //Set status of test case execution

            //Set other details on test execution
            tfsTestResult.ComputerName = Property.RcMachineId;
            tfsTestResult.DateStarted  = DateTime.Now;
            tfsTestResult.State        = TestResultState.InProgress;
            tfsTestResult.Save();
            return(true);
        }