Пример #1
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);
        }
Пример #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);
        }
Пример #3
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;
     }
 }
Пример #4
0
        public Task SaveResults(string runId, int suiteId)
        {
            return(Task.Factory.StartNew(() =>
            {
                // tell the spinner this task is starting
                ViewModelLocator.MainWindowViewModel.TaskManager.AddTask();

                // retrieve the info for the specified run
                RunInfo rfRunInfo = Services.Rainforest.Runs.GetSingle(runId);

                // check to see if the run is finished
                if (rfRunInfo.state != "complete" && rfRunInfo.state != "aborted")
                {
                    ViewModelLocator.MainWindowViewModel.TaskManager.RemoveTask();
                    throw new Core.ServiceException(Core.Error.RunNotComplete, runId);
                }

                // run has completed or has been aborted and is being processed, tag can be removed
                this.TFS.RemoveTag(suiteId, $"RUNID{runId}");

                // if run was aborted then drop results
                if (rfRunInfo.state == "aborted")
                {
                    ViewModelLocator.MainWindowViewModel.TaskManager.RemoveTask();
                    throw new Core.ServiceException(Core.Error.RunAborted, runId);
                }

                // Run was completed successfully
                // deserialize the RF tests info that were in the run, ids here are all rfIds, these are NOT JsonObjects.Test objects
                var anon = new[] { new { id = 0, result = "" } };
                var rfTestResults = JsonConvert.DeserializeAnonymousType(rfRunInfo.extras["tests"].ToString(), anon);

                // Get all the testpoints from the suite
                var testPointDict = TFS.Session.workingPlan
                                    .QueryTestPoints(String.Format("SELECT * FROM TestPoint WHERE SuiteId = {0}", suiteId))
                                    .ToDictionary(tp => tp.TestCaseId, tp => tp);

                // create a run in tfs to create results against
                ITestRun tfsTestRun = Session.workingPlan.CreateTestRun(false);

                // map the RF test results to a new enumerable with stored TFS id
                var refinedRFTestResults = rfTestResults.Select(r =>
                {
                    // retrieve the test from RF, need to search tag for matching TFS id
                    // each should have a tag already as it was ensured before the run was created
                    // TOEXPAND -> could possible add redundant check for no tags found in case manually removed
                    Test rfTest = Services.Rainforest.Tests.GetSingle(r.id.ToString());
                    string tfsId = Parse.ExtractIdFromTags("TFSID", rfTest.tags);
                    return new { rfid = r.id, verdict = r.result, tfsId = Int32.Parse(tfsId) };
                })
                                           .ToList();

                // go through RF results once to find the needed testpoints and add to run
                foreach (var result in refinedRFTestResults)
                {
                    // find test point for the matching TFS tc and add to run
                    ITestPoint testPoint = testPointDict[result.tfsId];
                    tfsTestRun.AddTestPoint(testPoint, testPoint.TestCaseWorkItem.Owner);
                }
                tfsTestRun.Save();

                // retrieve all the TFS results from the run
                Dictionary <int, ITestCaseResult> tfsTestResults = tfsTestRun.QueryResults().ToDictionary(r => r.TestCaseId, r => r);

                // go through RF results again to save the outcomes to the tfs results
                foreach (var result in refinedRFTestResults)
                {
                    ITestCaseResult tfsResult = tfsTestResults[result.tfsId];

                    switch (result.verdict)
                    {
                    case "passed":
                        tfsResult.Outcome = TestOutcome.Passed;
                        tfsResult.State = TestResultState.Completed;
                        break;

                    case "failed":
                        tfsResult.Outcome = TestOutcome.Failed;
                        tfsResult.State = TestResultState.Completed;
                        break;

                    default:
                        // TOEXPAND -> should never get here, verdict will always have a value
                        break;
                    }
                    tfsResult.State = TestResultState.Completed;
                    tfsResult.RunBy = Session.userTFId;
                    tfsResult.Save();
                }
                tfsTestRun.Save();
                tfsTestRun.Refresh();

                // tell the spinner this task is done
                ViewModelLocator.MainWindowViewModel.TaskManager.RemoveTask();
            }));
        }