private string GetLatestTestResult(int testId, ITestPlanCollection plans) { ITestPoint mostRecentPoint = null; foreach (ITestPlan plan in plans) { var points = plan.QueryTestPoints(string.Format("SELECT * FROM TestPoint WHERE TestCaseId = {0}", testId)); foreach (ITestPoint point in points) { if (mostRecentPoint == null || mostRecentPoint.LastUpdated < point.LastUpdated) { mostRecentPoint = point; } } } if (mostRecentPoint == null) { return("N/A"); } var mostRecent = "Not run"; if (mostRecentPoint.MostRecentResult != null) { mostRecent = mostRecentPoint.MostRecentResult.Outcome.ToString(); } return(mostRecent); }
public TestRun( TestEditInfo testEditInfo, ITestPoint testPoint, TeamFoundationIdentity currentIdentity) { _testEditInfo = testEditInfo; _testPoint = testPoint; _currentIdentity = currentIdentity; }
public TestCaseDescription(ITestPoint info, string url, string path) { Id = info.TestCaseId; Title = info.TestCaseWorkItem.Title; State = info.State.ToString(); AssignedTo = info.AssignedTo.DisplayName; Url = url; Path = path; }
public TfsTestPoint(ITestPoint originalTestPoint) { if (originalTestPoint == null) { throw new ArgumentNullException("originalTestCase"); } OriginalTestPoint = originalTestPoint; Id = originalTestPoint.Id; }
//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; } }
/// <summary> /// Gets the most recent execution comment. /// </summary> /// <param name="testPlan">The test plan.</param> /// <param name="testCaseId">The test case unique identifier.</param> /// <returns></returns> public static string GetMostRecentExecutionComment(ITestPlan testPlan, int testCaseId) { var testPoints = TestPointManager.GetTestPointsByTestCaseId(testPlan, testCaseId); ITestPoint lastTestPoint = null; if (testPoints.Count > 0) { lastTestPoint = testPoints.Last(); } string mostRecentExecutionComment = string.Empty; if (lastTestPoint != null && lastTestPoint.MostRecentResult != null && !string.IsNullOrEmpty(lastTestPoint.MostRecentResult.Comment)) { mostRecentExecutionComment = lastTestPoint.MostRecentResult.Comment; } return(mostRecentExecutionComment); }
/// <summary> /// Extracts the current result as string from a given Testpoint /// </summary> private string GetCurrentResult(ITestPoint tp) { // check for cases where causes are unknown if (tp.State == TestPointState.None || tp.State == TestPointState.InProgress || tp.State == TestPointState.MaxValue) { return("Unknown"); } // if 'Ready' then cannot look at most recent result as tp is waiting for new outcome if (tp.State == TestPointState.Ready) { return("Active"); } // leftover cases where state == 'Completed' or 'NotReady', can extract most recent outcome return(Enum.GetName(typeof(TestOutcome), tp.MostRecentResultOutcome)); }
/// <summary> /// Gets the most recent test case result. /// </summary> /// <param name="testPlan">The test plan.</param> /// <param name="testCaseId">The test case unique identifier.</param> /// <returns></returns> public static string GetMostRecentTestCaseResult(ITestPlan testPlan, int testCaseId) { var testPoints = TestPointManager.GetTestPointsByTestCaseId(testPlan, testCaseId); ITestPoint lastTestPoint = null; if (testPoints.Count > 0) { lastTestPoint = testPoints.Last(); } string mostRecentResult = "Active"; ITestCaseResult lastTestCaseResult = null; if (lastTestPoint != null) { lastTestCaseResult = lastTestPoint.MostRecentResult; } if (lastTestCaseResult != null) { mostRecentResult = lastTestCaseResult.Outcome.ToString(); } return(mostRecentResult); }
//----------------------------------------------------------------- // Run a testpoint (or cancel a running one private async void runTestPoint_Click(object sender, EventArgs e) { runTestPoint.BackColor = default(Color); // If starting a new testpoint if (runTestPoint.Text.Contains("Run")) { // Clear previous progress information testProgressBar.Value = 0; testProgressBar.BarText = ""; TaskInfo.GlobalAborted = false; if (String.IsNullOrEmpty(operatorId.Text)) { MessageBox.Show("Please enter operator ID"); operatorId.Select(); } else if (testPointSelect.SelectedValue == null) { /* - TODO - need to do anything here? this should be an odd special case */ } else { ITestPoint tp = testPointSelect.SelectedValue as ITestPoint; bool allowTpToRun = true; if (verifyTestPointVersion) { // https://stackoverflow.com/q/11848785 string tpDllName = Assembly.GetAssembly(tp.GetType()).GetName().Name; string tpVersion = Assembly.GetAssembly(tp.GetType()).GetName().Version.ToString(); string tpInfo = tpDllName + " " + tpVersion; if (MessageBox.Show("Selected test point is version:\n\n" + tpInfo + "\n\n" + "Does this match the test station certification sticker?", "Verify Test Point", MessageBoxButtons.YesNo) == DialogResult.No) { allowTpToRun = false; } } if (verifyEquipmentInCal) { if (MessageBox.Show("Is all test equipment within their cal dates?", "Verify In Cal", MessageBoxButtons.YesNo) == DialogResult.No) { allowTpToRun = false; } } if (allowTpToRun) { requestTestCancel = new CancellationTokenSource(); tp.Database = paperlessDb; // Set the selected tasks to run tp.TasksToRun = testPicker.SelectedTasks; Dictionary <string, object> flags = GetFlags(); tp.Flags = flags; try { // Disable controls AllowFormControls(false); // Start the log testProgressBar.BarText = "Enabling Logging"; await Task.Run(() => { StartLogging(tp.DisplayName); }); // Set the flags if (tp.Tasks != null) { foreach (var tt in tp.Tasks) { tt.Flags = flags; tt.Database = paperlessDb; } } // Run the test testProgressBar.BarText = "Starting Test Point " + tp.DisplayName; await tp.Run(requestTestCancel.Token); testProgressBar.BarText = "Finished"; } // If it was cancelled catch (TaskCanceledException) { testProgressBar.BarText = "Cancelled"; } // If the test had an error it was expecting catch (ApplicationException ex) { MessageBox.Show("Error during test: " + ex.Message); testProgressBar.BarText = "Finished: Error"; } // If there was a different error catch (Exception ex) { MessageBox.Show("Unexpected exception: " + ex.Message); testProgressBar.BarText = "Finished: Error"; } finally { } if (clearOperatorId) { // I don't think that the ID should be cleared // If the test wasn't cancelled, clear the operator ID so another test can be run if (!requestTestCancel.IsCancellationRequested) { operatorId.Text = ""; } } requestTestCancel.Dispose(); // The Progress event that is reporting the state of the last task has not been handled // Use DoEvents to make sure it is (and disable the form around it to avoid side effects) // http://stackoverflow.com/a/5183623 this.Enabled = false; await Task.Run(() => { Application.DoEvents(); }); this.Enabled = true; // Finish test testProgressBar.BarText = "Finished"; testProgressBar.Value = testProgressBar.Maximum; FinishLogging(); AllowFormControls(true); if (clearSerialNumber) { uutSerialNumber.Clear(); } uutSerialNumber.Select(); } } } // A test is already running, so cancel it else { // Cancel the test requestTestCancel.Cancel(); TaskInfo.GlobalAborted = true; } }
//----------------------------------------------------------------- // Set menu and controls when the testpoint is changed private async void testPointSelect_SelectedIndexChanged(object sender, EventArgs e) { AllowFormControls(false); ITestPoint selectedTp = testPointSelect.SelectedValue as ITestPoint; testPointInfo.ForeColor = default(Color); try { if (previousTp != selectedTp || errorSelectingIndex) { testProgressBar.Value = 10; testProgressBar.BarText = "Clearing Previous Testpoint"; // Close the previous ports if there were any if (previousTp != null) { IHoldResources prevTask = previousTp as IHoldResources; if (prevTask != null) { await prevTask.UnSelect(); } IHazAPort prevPort = previousTp as IHazAPort; if (prevPort != null) { int i = tabControl1.TabPages.Count - 1; foreach (var port in prevPort.Ports) { //port.Cancel(); if (portTabsActive) { TabPage tp = tabControl1.TabPages[i]; tp.Controls.Clear(); tabControl1.TabPages.RemoveAt(i); tp.Dispose(); i--; } } } portTabsActive = false; } previousTp = selectedTp; // Set the status interface selectedTp.StatusHandle = progressHandler; var flags = GetFlags(); selectedTp.Flags = flags; testProgressBar.Value = 80; testProgressBar.BarText = "Creating Controls"; // Update the window to pick which tasks to run if (selectedTp.Tasks != null) { testPicker.TaskList = selectedTp.Tasks.Select(s => s.DisplayName).ToList(); } else { testPicker.TaskList = null; } // Update the testpoint control (or hide the tab if the TP doesn't have one // Size to grow the GUI by is there is a large test point control int addX = 0; int addY = 0; // Clear any existing test point control testPointControls.Controls.Clear(); UserControl testControl = selectedTp.TestControl; // If the testpoint doesn't have a control, hide the control tab if (testControl == null) { if (!controlsHidden) { testPointControls.SetInvisible(); controlsHidden = true; } this.Size = this.MinimumSize; } // Otherwise configure to show the test point control else { // Show the tab if it isn't already if (controlsHidden) { testPointControls.SetVisible(tabControl1); controlsHidden = false; } // Add the control testPointControls.Controls.Add(testControl); testControl.Location = new Point(0, 0); tabControl1.SelectedTab = testPointControls; Size controlSize = testControl.Size; // Calculate form size adjustment addX = Math.Max(0, controlSize.Width - 700); addY = Math.Max(0, controlSize.Height - 380); // clear anchor styles first to avoid problems testControl.Anchor = AnchorStyles.Top | AnchorStyles.Left; } // Set the form size this.Size = new Size(this.MinimumSize.Width + addX, this.MinimumSize.Height + addY); // Set the anchor after resize so it looks right if (testControl != null) { testControl.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right); } // Get the version information string tpDllName = Assembly.GetAssembly(selectedTp.GetType()).GetName().Name; string tpVersion = Assembly.GetAssembly(selectedTp.GetType()).GetName().Version.ToString(); this.Text = titleText + " : " + tpDllName + " " + tpVersion; IHoldResources thisTask = selectedTp as IHoldResources; if (thisTask != null) { await thisTask.Select(); } // Open the new ports if there are any IHazAPort portObject = selectedTp as IHazAPort; if (portObject != null) { int i = 0; foreach (var port in portObject.Ports) { port.Start(); if (engineeringMode.Checked) { TabPage tp = new TabPage(); //tp.Name = "Port " + i.ToString(); tp.Text = "Port " + i.ToString(); UutCompact ctrl = null; if (portControls.ContainsKey(selectedTp.TestPointName + i.ToString())) { ctrl = portControls[selectedTp.TestPointName + i.ToString()]; } else { ctrl = new UutCompact(); ctrl.Port = port; portControls.Add(selectedTp.TestPointName + i.ToString(), ctrl); } tp.Controls.Add(ctrl); ctrl.Location = new Point(0, 0); ctrl.Size = new Size(tabControl1.Size.Width - 10, tabControl1.Size.Height - 30); tabControl1.TabPages.Add(tp); i++; portTabsActive = true; } } } } testProgressBar.Value = 0; testProgressBar.BarText = "Ready"; errorSelectingIndex = false; runTestPoint.Enabled = true; runTestPoint.BackColor = Color.Yellow; } catch (Exception ex) { errorSelectingIndex = true; runTestPoint.Enabled = false; if (selectedTp.StatusHandle != null) { StatusInfo.ReportException(selectedTp.StatusHandle, "SelectedIndexChanged", ex); } // Clear any existing test point control testPointControls.Controls.Clear(); MessageBox.Show(ex.ToString(), "Error Selecting Testpoint", MessageBoxButtons.OK, MessageBoxIcon.Error); } AllowFormControls(true); }
public TestPointInfoStream(InfoStream @delegate, ITestPoint testPoint) { this.@delegate = @delegate ?? new NullInfoStream(); this.testPoint = testPoint; }
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(); })); }
/// <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); }
//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; } }
//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; } }
public static IndexWriter MockIndexWriter(Directory dir, IndexWriterConfig conf, ITestPoint testPoint) { conf.SetInfoStream(new TestPointInfoStream(conf.InfoStream, testPoint)); return(new IndexWriter(dir, conf)); }
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); }