/// <summary> /// Prepares development environment for test case running. /// This has to be executed from UI thread. /// </summary> /// <param name="testInformation"></param> public static void PreRunTestCase(TestInformation testInformation) { testInformation.Stop = false; try { if (testInformation.Debug) { if (!testRunners.ContainsKey(testInformation.AssemblyPath)) { return; } RunnerInformation runnerInformation = testRunners[testInformation.AssemblyPath]; // Attaching the NunitRunner process to debugger. DTE dte = (DTE)Package.GetGlobalService(typeof(DTE)); foreach (EnvDTE.Process localProcess in dte.Debugger.LocalProcesses) { if (localProcess.ProcessID == runnerInformation.Process.Id) { int processId = runnerInformation.Process.Id; string localProcessName = localProcess.Name; localProcess.Attach(); } } } } catch (Exception ex) { Trace.TraceError("Error attaching process to debugger: " + ex.ToString()); } }
public LingualTest(TestInformation testInformation) : base(new TestName { FullName = testInformation.SortableName, Name = testInformation.AssertDescription }) { _test = testInformation.Test; }
/// <summary> /// Recovers development environment from test case running. /// This has to be executed from UI thread. /// </summary> /// <param name="testInformation"></param> public static void PostRunTestCase(TestInformation testInformation) { try { if (testInformation.Debug) { if (!testRunners.ContainsKey(testInformation.AssemblyPath)) { return; } RunnerInformation runnerInformation = testRunners[testInformation.AssemblyPath]; // Detaching the NunitRunner process from debugger. DTE dte = (DTE)Package.GetGlobalService(typeof(DTE)); foreach (EnvDTE.Process localProcess in dte.Debugger.DebuggedProcesses) { if (localProcess.ProcessID == runnerInformation.Process.Id) { localProcess.Detach(true); } } } } catch (Exception ex) { Trace.TraceError("Error detaching process from debugger: " + ex.ToString()); } }
/// <summary> /// Aborts execution of test case by restarting the test runner process. /// </summary> /// <param name="testInformation"></param> public static void AbortTestCase(TestInformation testInformation) { if (!testRunners.ContainsKey(testInformation.AssemblyPath)) { return; } testInformation.Stop = true; StartRunner(testInformation.AssemblyPath); }
/// <summary> /// The set test information data. /// </summary> /// <param name="testInformation"> /// The test information. /// </param> public void SetTestInformationData(TestInformation testInformation) { TestInformation = testInformation; this.textBoxCompany.Text = TestInformation.Company; this.textBoxDeviceId.Text = TestInformation.DeviceId; this.textBoxDeviceSerialNumber.Text = TestInformation.DeviceSerialNumber; this.textBoxDeviceTypeName.Text = TestInformation.DeviceType; this.textBoxNameOfTester.Text = TestInformation.NameOfTester; }
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { TestDetailsForm testDetailsForm = new TestDetailsForm(); DataRow row = ((DataRowView)dataGridView1.Rows[e.RowIndex].DataBoundItem).Row; TestInformation testInformation = (TestInformation)row["TestInformation"]; testDetailsForm.SetTestInformation(testInformation); testDetailsForm.ShowDialog(); } }
private void ProcessTestResult(string message) { Match match = testResultPattern.Match(message); TestInformation info = new TestInformation { Name = match.Groups[1].Value, Result = TestResultFromString(match.Groups[2].Value) }; if (info.Result == TestResult.Passed) { ui.AddTest(info); } }
private void ProcessTestResult(string message) { Match match = testResultPattern.Match(message); TestInformation info = new TestInformation(); info.name = match.Groups[1].Value; info.result = TestResultFromString(match.Groups[2].Value); if (info.result == TestResult.PASSED) { ui.AddTest(info); } }
public void TestRunningSuccessTest() { RunnerServer runnerServer = new RunnerServer("TestVisualNunitRunner", "VisualNunitTests.dll"); RunnerClient runnerClient = new RunnerClient("TestVisualNunitRunner", Process.GetCurrentProcess()); TestInformation testInformation = new TestInformation(); testInformation.TestName = "VisualNunitTests.ExampleTestOne.TestOneSuccess"; runnerClient.RunTest(testInformation); Assert.AreEqual(TestState.Success, testInformation.TestState); runnerClient.Disconnect(); }
public void SetTestInformation(TestInformation testInformation) { this.textBox1.Text = testInformation.FailureMessage; DataTable table = new DataTable(); table.Columns.Add("File", typeof(String)); table.Columns.Add("Method", typeof(String)); table.Columns.Add("Row", typeof(String)); if (testInformation.FailureStackTrace != null) { StringReader reader = new StringReader(testInformation.FailureStackTrace); string line; while ((line = reader.ReadLine()) != null) { if (line.StartsWith("at ")) { if (line.Contains(" in ")) { int methodStartIndex = 3; int methodEndIndex = line.LastIndexOf(" in "); int fileStartIndex = line.LastIndexOf(" in ") + 4; int fileEndIndex = line.LastIndexOf(":line "); int rowStartIndex = line.LastIndexOf(":line ") + 5; int rowEndIndex = line.Length; String method = line.Substring(methodStartIndex, methodEndIndex - methodStartIndex); String file = line.Substring(fileStartIndex, fileEndIndex - fileStartIndex); String row = line.Substring(rowStartIndex, rowEndIndex - rowStartIndex); table.Rows.Add(file, method, row); } else { int methodStartIndex = 3; int methodEndIndex = line.Length; String method = line.Substring(methodStartIndex, methodEndIndex - methodStartIndex); table.Rows.Add(null, method, null); } } else { break; } } } dataGridView1.DataSource = table; }
public void TestRunningExceptionTest() { RunnerServer runnerServer = new RunnerServer("TestVisualNunitRunner", "VisualNunitTests.dll"); RunnerClient runnerClient = new RunnerClient("TestVisualNunitRunner", Process.GetCurrentProcess()); TestInformation testInformation = new TestInformation(); testInformation.TestName = "VisualNunitTests.ExampleTestOne.TestOneException"; runnerClient.RunTest(testInformation); Assert.AreEqual(TestState.Failure, testInformation.TestState); Assert.AreEqual("Failure: System.Exception : Test Exception", testInformation.FailureMessage); runnerClient.Disconnect(); }
private void ProcessFileError(string message) { Match match = testErrorFilePattern.Match(message); TestInformation info = new TestInformation(); info.name = match.Groups[1].Value; info.functionName = match.Groups[2].Value; info.path = match.Groups[3].Value; info.line = int.Parse(match.Groups[4].Value); if (ui.IsTesting(info.functionName)) { ui.SetTestPathAndLine(info); } }
/// <summary> /// Runs a single test case in separate NunitRunner process synchronously. /// </summary> /// <param name="testInformation">Information identifying the test case and containing place holders for result information.</param> /// <param name="debug">Set to true to enable debug mode.</param> public static void RunTestCase(TestInformation testInformation, bool explicitRun) { if (!testRunners.ContainsKey(testInformation.AssemblyPath)) { return; } RunnerInformation runnerInformation = testRunners[testInformation.AssemblyPath]; try { runnerInformation.Client.RunTest(testInformation, explicitRun); } catch (Exception e) { Trace.TraceError("Error running test:" + e.ToString()); } }
private void ProcessTestError(string message) { Match match = testErrorPattern.Match(message); string name = match.Groups[1].Value; string error = match.Groups[2].Value; TestResult result = TestResult.Failed; if (Regex.IsMatch(error, "Error:")) { result = TestResult.Error; } TestInformation info = new TestInformation { Name = name, Tooltip = error, Result = result }; ui.AddTest(info); }
private void ProcessTestError(string message) { Match match = testErrorPattern.Match(message); string name = match.Groups[1].Value; string error = match.Groups[2].Value; TestResult result = TestResult.FAILED; if (Regex.IsMatch(error, "Error:")) { result = TestResult.ERROR; } TestInformation info = new TestInformation(); info.name = name; info.tooltip = error; info.result = result; ui.AddTest(info); }
/// <summary> /// Create this viewmodel with edit mode on so it means that it is editing an existing test /// </summary> /// <param name="TestInfo"></param> public TestEditorBasicInformationEditorViewModel(TestInformation TestInfo) { CreateCommands(); if (TestInfo == null) { EditingModeOn = false; } else { EditingModeOn = true; mOriginalInfo = TestInfo; // Fill initial values Name = TestInfo.Name; DurationHours = TestInfo.Duration.Hours.ToString(); DurationMinutes = TestInfo.Duration.Minutes.ToString(); DurationSeconds = TestInfo.Duration.Seconds.ToString(); Tags = TestInfo.Tags; Note = TestInfo.Note; } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "Debug") { if (currentTest == null) { statusButton.Image = emptyIcon; statusLabel.Text = ""; DataRow dataRow = ((DataRowView)dataGridView1.CurrentRow.DataBoundItem).Row; currentTest = (TestInformation)dataRow["TestInformation"]; currentTest.TestState = TestState.None; currentTest.FailureMessage = ""; currentTest.FailureStackTrace = ""; currentTest.Time = TimeSpan.Zero; dataRow["Success"] = currentTest.TestState; dataRow["Time"] = ""; dataRow["Message"] = currentTest.FailureMessage; currentTest.Debug = true; testsToRunStartCount = 1; runTestsButton.Text = "Stop"; runTestsButton.Image = stopIcon; NunitManager.PreRunTestCase(currentTest); testRunWorker.RunWorkerAsync(); } } if (dataGridView1.Columns[e.ColumnIndex].Name == "Stacktrace") { TestDetailsForm testDetailsForm = new TestDetailsForm(); DataRow row = ((DataRowView)dataGridView1.CurrentRow.DataBoundItem).Row; TestInformation testInformation = (TestInformation)row["TestInformation"]; testDetailsForm.SetTestInformation(testInformation); testDetailsForm.ShowDialog(); } }
private void runTests_Click(object sender, EventArgs e) { if (currentTest == null) { statusButton.Image = emptyIcon; statusLabel.Text = ""; if (dataGridView1.SelectedRows.Count == 0) { foreach (DataGridViewRow row in dataGridView1.Rows) { DataRow dataRow = ((DataRowView)row.DataBoundItem).Row; TestInformation testInformation = (TestInformation)dataRow["TestInformation"]; testInformation.Debug = false; testInformation.TestState = TestState.None; testInformation.FailureMessage = ""; testInformation.FailureStackTrace = ""; testInformation.Time = TimeSpan.Zero; dataRow["Success"] = testInformation.TestState; dataRow["Time"] = ""; dataRow["Message"] = testInformation.FailureMessage; testsToRun.Enqueue(testInformation); } } else { List <DataRow> dataRows = new List <DataRow>(); foreach (DataGridViewRow row in dataGridView1.SelectedRows) { dataRows.Add(((DataRowView)row.DataBoundItem).Row); } dataRows.Reverse(); foreach (DataRow dataRow in dataRows) { TestInformation testInformation = (TestInformation)dataRow["TestInformation"]; testInformation.Debug = false; testInformation.TestState = TestState.None; testInformation.FailureMessage = ""; testInformation.FailureStackTrace = ""; testInformation.Time = TimeSpan.Zero; dataRow["Success"] = testInformation.TestState; dataRow["Time"] = ""; dataRow["Message"] = testInformation.FailureMessage; testsToRun.Enqueue(testInformation); } } if (testsToRun.Count > 0) { testsToRunStartCount = testsToRun.Count; currentTest = testsToRun.Dequeue(); runTestsButton.Text = "Stop"; runTestsButton.Image = stopIcon; NunitManager.PreRunTestCase(currentTest); testRunWorker.RunWorkerAsync(); } } else { testsToRun.Clear(); testsToRunStartCount = 1; NunitManager.AbortTestCase(currentTest); } }
private void testListWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { string assemblyPath = currentlyLoadingProject.AssemblyPath; DataTable dataTable = (DataTable)dataGridView1.DataSource; if (loadedTestCases != null) { foreach (string testCase in loadedTestCases) { TestInformation testInformation = new TestInformation(); testInformation.AssemblyPath = assemblyPath; testInformation.TestName = testCase; string[] nameParts = testCase.Split('.'); string testName; string caseName; string testNamespace; if (nameParts.Length > 2) { testName = nameParts[nameParts.Length - 1]; caseName = nameParts[nameParts.Length - 2]; testNamespace = testCase.Substring(0, testCase.Length - (caseName.Length + testName.Length + 2)); } else { testName = nameParts[nameParts.Length - 1]; caseName = nameParts[nameParts.Length - 2]; testNamespace = ""; } if (namespaceComboBox.SelectedIndex != -1 && !testNamespace.Equals(namespaceComboBox.SelectedItem)) { continue; } if (caseComboBox.SelectedIndex != -1 && !caseName.Equals(caseComboBox.SelectedItem)) { continue; } if (!namespaceComboBox.Items.Contains(testNamespace)) { namespaceComboBox.Items.Add(testNamespace); } if (!caseComboBox.Items.Contains(caseName)) { caseComboBox.Items.Add(caseName); } DataRow row = dataTable.Rows.Add(new Object[] { TestState.None, testNamespace, caseName, testName, "", testInformation.FailureMessage, testInformation }); testInformation.DataRow = row; } } dataGridView1.ClearSelection(); if (projectsToLoad.Count > 0 && !testListWorker.IsBusy) { currentlyLoadingProject = projectsToLoad.Dequeue(); testListWorker.RunWorkerAsync(); } }
public void SetTestInformation(TestInformation testInformation) { this.textBox1.Text = testInformation.FailureMessage + "\r\n\r\nStack Trace:\r\n" + testInformation.FailureStackTrace; }
public LingualTest(TestInformation testInformation) : base(new TestName {FullName = testInformation.SortableName, Name = testInformation.AssertDescription}) { _test = testInformation.Test; }
private void testRunWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { NunitManager.PostRunTestCase(currentTest); { DataRow dataRow = currentTest.DataRow; dataRow["Success"] = currentTest.TestState; dataRow["Time"] = currentTest.Time.TotalSeconds.ToString(); dataRow["Message"] = currentTest.FailureMessage; } if (testsToRun.Count > 0) { currentTest = testsToRun.Dequeue(); NunitManager.PreRunTestCase(currentTest); testRunWorker.RunWorkerAsync(); } else { currentTest = null; runTestsButton.Text = "Run"; runTestsButton.Image = runIcon; int successes = 0; int failures = 0; int aborts = 0; int unknowns = 0; int total = dataGridView1.Rows.Count; foreach (DataGridViewRow row in dataGridView1.Rows) { DataRow dataRow = ((DataRowView)row.DataBoundItem).Row; TestState testState = (TestState)dataRow["Success"]; if (TestState.Success.Equals(testState)) { successes++; } else if (TestState.Failure.Equals(testState)) { failures++; } else if (TestState.Aborted.Equals(testState)) { aborts++; } else { unknowns++; } } statusButton.Image = emptyIcon; if (successes == total) { statusButton.Image = successIcon; } if (failures != 0) { statusButton.Image = failureIcon; } statusLabel.Text = "Total tests run: " + (successes + failures) + " Failures: " + failures + " " + (successes + failures != 0?"(" + (100 * failures / (successes + failures)) + "%)":""); } }
public ForecastSteps(IWebDriver driver, TestInformation testInfo) { _driver = driver; _testInfo = testInfo; }
public LoginSteps(IWebDriver driver, TestInformation testInfo) { _driver = driver; _testInfo = testInfo; _reporter.CreateScenario(FeatureContext.Current.FeatureInfo.Title, ScenarioContext.Current.ScenarioInfo.Title, "Scenario"); }
public Test(TestNumber number, string name) { Information = new TestInformation(number, name); Result = new TestResult(); }
public static void Main(/*string[] args*/) { var boolControl = new Control() { Name = "boolControl", States = new States() { new State() { Name = "true" }, new State() { Name = "false" } } }; var originalStates = new States() { new State() { Name = "testState1" }, new State() { Name = "testState2" } }; var originalControl = new Control() { Name = "testControl", States = originalStates }; var originalControls = new Controls() { originalControl }; var originalAction = new Action() { Name = "testAction", Controls = new Controls() { boolControl, originalControl } }; var originalActions = new Actions() { originalAction }; var originalTestInformation = new TestInformation() { States = originalStates, Controls = originalControls, Actions = originalActions }; // Save the State to a string. string serializedTestInformation = XamlWriter.Save(originalTestInformation); Console.WriteLine($"{serializedTestInformation}"); // Load the test information StringReader stringReader = new StringReader(serializedTestInformation); XmlReader xmlReader = XmlReader.Create(stringReader); var readerLoadedTestInformation = XamlReader.Load(xmlReader) as ITestInformation ?? new TestInformation(); readerLoadedTestInformation.States.ToList().ForEach(state => { Console.WriteLine($"State name={state.Name}"); }); readerLoadedTestInformation.Controls.ToList().ForEach(control => { Console.WriteLine($"Control name={control.Name}"); control.States.ToList().ForEach(state => { Console.WriteLine($"State name={state.Name}"); }); }); readerLoadedTestInformation.Actions.ToList().ForEach(action => { Console.WriteLine($"Action name={action.Name}"); action.Controls.ToList().ForEach(control => { Console.WriteLine($"Control name={control.Name}"); control.States.ToList().ForEach(state => { Console.WriteLine($"State name={state.Name}"); }); }); }); var internals = readerLoadedTestInformation.MakeTestsInformationInternal(); internals.Actions.ToList().ForEach(action => { Console.WriteLine($"Internal Action name={action.Name}"); action.Controls.ToList().ForEach(control => { Console.WriteLine($"Internal Control name={control.Name}"); control.States.ToList().ForEach(state => { Console.WriteLine($"Internal State name={state.Name}"); }); }); }); }