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 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();
        }
예제 #3
0
        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;
        }
예제 #4
0
        /// <summary>
        /// Signals RunnerServer to execute the test and fills in test result to test information object.
        /// </summary>
        /// <param name="testInformation">The test to be executed.</param>
        public void RunTest(TestInformation testInformation, bool explicitRun)
        {
            // Signal the test execution.
            String testName = testInformation.TestName;
            if (explicitRun)
            {
                testName += "!";
            }

            byte[] testNameBytes = Encoding.UTF8.GetBytes(testName);
            pipe.Write(testNameBytes, 0, testNameBytes.Length);
            pipe.Flush();

            // Blocking read to the test result.
            string resultXml = "";
            while(true)
            {
                int readByteCount = pipe.Read(readBuffer, 0, readBuffer.Length);
                resultXml += Encoding.UTF8.GetString(readBuffer, 0, readByteCount);

                // Thread lock to allow for graceful exit from result reading loop.
                lock (this)
                {
                    if(!pipe.IsConnected)
                    {
                        break;
                    }
                    if(pipe.IsMessageComplete)
                    {
                        break;
                    }
                }
            }

            // If user aborted then fill manually result information else parse it from result xml.
            if (testInformation.Stop)
            {
                // Filling in abort information.
                testInformation.TestState = TestState.Aborted;
                testInformation.FailureMessage = "Aborted";
                testInformation.Time = TimeSpan.Zero;
            }
            else
            {
                // Parsing a result XML received from NunitRunner standard output.
                XmlDocument result = new XmlDocument();
                result.LoadXml(resultXml);

                // Filling in general information from result.
                XmlNode caseNode = result.GetElementsByTagName("test-case").Item(0);
                foreach (XmlAttribute attribute in caseNode.Attributes)
                {
                    if (attribute.Name == "time")
                    {
                        testInformation.Time = TimeSpan.FromSeconds(Double.Parse(attribute.Value.Replace(".",DecimalDelimiter)));
                    }
                    if (attribute.Name == "success")
                    {
                        if ("True".Equals(attribute.Value))
                        {
                            testInformation.TestState = TestState.Success;
                            testInformation.FailureMessage = "Success";
                        }
                        else
                        {
                            testInformation.TestState = TestState.Failure;
                            testInformation.FailureMessage = "Failure: ";
                        }
                    }
                }

                // Filling in failure information from result.
                testInformation.FailureStackTrace = "";
                foreach (XmlNode failureNode in caseNode.ChildNodes)
                {
                    if (failureNode.LocalName == "failure")
                    {
                        foreach (XmlNode informationNode in failureNode)
                        {
                            if (informationNode.LocalName == "message")
                            {
                                testInformation.FailureMessage += informationNode.InnerText;
                            }
                            if (informationNode.LocalName == "stack-trace")
                            {
                                testInformation.FailureStackTrace = informationNode.InnerText;
                            }
                        }
                    }
                    if (failureNode.LocalName == "reason")
                    {
                        foreach (XmlNode informationNode in failureNode)
                        {
                            if (informationNode.LocalName == "message")
                            {
                                testInformation.FailureMessage += informationNode.InnerText;
                            }
                        }
                    }
                }

            }
        }
예제 #5
0
 public void SetTestInformation(TestInformation testInformation)
 {
     this.textBox1.Text = testInformation.FailureMessage + "\r\n\r\nStack Trace:\r\n" + testInformation.FailureStackTrace;
 }
예제 #6
0
        /// <summary>
        /// Signals RunnerServer to execute the test and fills in test result to test information object.
        /// </summary>
        /// <param name="testInformation">The test to be executed.</param>
        public void RunTest(TestInformation testInformation)
        {
            // Signal the test execution.
            byte[] testNameBytes = Encoding.UTF8.GetBytes(testInformation.TestName);
            pipe.Write(testNameBytes, 0, testNameBytes.Length);
            pipe.Flush();

            // Blocking read to the test result.
            string resultXml = "";

            while (true)
            {
                int readByteCount = pipe.Read(readBuffer, 0, readBuffer.Length);
                resultXml += Encoding.UTF8.GetString(readBuffer, 0, readByteCount);

                // Thread lock to allow for graceful exit from result reading loop.
                lock (this)
                {
                    if (!pipe.IsConnected)
                    {
                        break;
                    }
                    if (pipe.IsMessageComplete)
                    {
                        break;
                    }
                }
            }

            // If user aborted then fill manually result information else parse it from result xml.
            if (testInformation.Stop)
            {
                // Filling in abort information.
                testInformation.TestState      = TestState.Aborted;
                testInformation.FailureMessage = "Aborted";
                testInformation.Time           = TimeSpan.Zero;
            }
            else
            {
                // Parsing a result XML received from NunitRunner standard output.
                XmlDocument result = new XmlDocument();
                result.LoadXml(resultXml);

                // Filling in general information from result.
                XmlNode caseNode = result.GetElementsByTagName("test-case").Item(0);
                foreach (XmlAttribute attribute in caseNode.Attributes)
                {
                    if (attribute.Name == "time")
                    {
                        testInformation.Time = TimeSpan.FromSeconds(Double.Parse(attribute.Value.Replace(".", DecimalDelimiter)));
                    }
                    if (attribute.Name == "success")
                    {
                        if ("True".Equals(attribute.Value))
                        {
                            testInformation.TestState      = TestState.Success;
                            testInformation.FailureMessage = "Success";
                        }
                        else
                        {
                            testInformation.TestState      = TestState.Failure;
                            testInformation.FailureMessage = "Failure: ";
                        }
                    }
                }

                // Filling in failure information from result.
                testInformation.FailureStackTrace = "";
                foreach (XmlNode failureNode in caseNode.ChildNodes)
                {
                    if (failureNode.LocalName == "failure")
                    {
                        foreach (XmlNode informationNode in failureNode)
                        {
                            if (informationNode.LocalName == "message")
                            {
                                testInformation.FailureMessage += informationNode.InnerText;
                            }
                            if (informationNode.LocalName == "stack-trace")
                            {
                                testInformation.FailureStackTrace = informationNode.InnerText;
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        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))+"%)":"");

            }
        }
예제 #8
0
        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();
            }
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        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();
            }
        }