예제 #1
0
파일: NUnit.cs 프로젝트: Wowbies/reportunit
        /// <summary>
        /// Processes the fixture level blocks
        /// Adds all tests to the output
        /// </summary>
        private void ProcessFixtureBlocks()
        {
            logger.Info("Building fixture blocks...");

            string errorMsg = null;
            string descMsg = null;
            XmlNodeList testSuiteNodes = _doc.SelectNodes("//test-suite[@type='TestFixture']");
            // if other test runner type is outputting its results in nunit format - then may not have full markup - so just get all "test-suite" nodes
            if (testSuiteNodes.Count == 0)
            {
                testSuiteNodes = _doc.SelectNodes(string.Format("//test-suite[contains(@name, '{0}.')]", _assemblyNameWithoutExtension));

            }
            int testCount = 0;

            // run for each test-suite
            foreach (XmlNode suite in testSuiteNodes)
            {
                var testSuite = new TestSuite();
                testSuite.Name = nodeFriendlyName(suite,_assemblyNameWithoutExtension);

                if (suite.Attributes["start-time"] != null && suite.Attributes["end-time"] != null)
                {
                    var startTime = suite.Attributes["start-time"].InnerText.Replace("Z", "");
                    var endTime = suite.Attributes["end-time"].InnerText.Replace("Z", "");

                    testSuite.StartTime = startTime;
                    testSuite.EndTime = endTime;
                    testSuite.Duration = DateTimeHelper.DifferenceInMilliseconds(startTime, endTime);
                }
                else if (suite.Attributes["time"] != null)
                {
                    double duration;
                    if (double.TryParse(suite.Attributes["time"].InnerText.Replace("Z", ""), out duration))
                    {
                        testSuite.Duration = duration;
                    }

                    testSuite.StartTime = duration.ToString();
                }

                // check if the testSuite has any errors (ie error in the TestFixtureSetUp)
                var testSuiteFailureNode = suite.SelectSingleNode("failure");
                if (testSuiteFailureNode != null && testSuiteFailureNode.HasChildNodes)
                {
                    errorMsg = descMsg = "";
                    var message = testSuiteFailureNode.SelectSingleNode(".//message");

                    if (message != null)
                    {
                        errorMsg = message.InnerText.Trim();
                        errorMsg += testSuiteFailureNode.SelectSingleNode(".//stack-trace") != null ? " -> " + testSuiteFailureNode.SelectSingleNode(".//stack-trace").InnerText.Replace("\r", "").Replace("\n", "") : "";
                    }
                    testSuite.StatusMessage = errorMsg;
                }

                // add each test of the test-fixture
                foreach (XmlNode testcase in suite.SelectNodes(".//test-case"))
                {
                    errorMsg = descMsg = "";

                    var tc = new Test();
                    var tcAssemblyName = testcase.Attributes["name"].InnerText;

                    var tcFriendlyName = nodeFriendlyName(testcase, _assemblyNameWithoutExtension, testSuite.Name);
                    tc.Name = tcFriendlyName;
                    // figure out the status reslt of the test
                    if (testcase.Attributes["result"] != null)
                    {
                        tc.Status = testcase.Attributes["result"].InnerText.AsStatus();
                    }
                    else if (testcase.Attributes["executed"] != null && testcase.Attributes["success"] != null)
                    {
                        bool success, executed;
                        bool.TryParse(testcase.Attributes["executed"].InnerText, out executed);
                        bool.TryParse(testcase.Attributes["success"].InnerText, out success);

                        tc.Status = success ? Status.Passed :
                                            executed ? Status.Failed : Status.Skipped;
                    }
                    else if (testcase.Attributes["success"] != null)
                    {
                        bool success;
                        bool.TryParse(testcase.Attributes["success"].InnerText, out success);
                        tc.Status = success ? Status.Passed : Status.Failed;
                    }

                    if (testcase.Attributes["time"] != null)
                    {
                        try
                        {
                            TimeSpan d;
                            var durationTimeSpan = testcase.Attributes["duration"].InnerText;
                            if (TimeSpan.TryParse(durationTimeSpan, out d))
                            {
                                tc.Duration = d.TotalMilliseconds;
                            }
                        }
                        catch (Exception) { }
                    }

                    var categories = testcase.SelectNodes(".//property[@name='Category']");

                    foreach (XmlNode category in categories)
                    {
                        tc.Categories.Add(category.Attributes["value"].InnerText);
                    }

                    var message = testcase.SelectSingleNode(".//message");

                    if (message != null)
                    {
                        errorMsg = "<pre class='stack-trace'>" + message.InnerText.Trim();
                        errorMsg += testcase.SelectSingleNode(".//stack-trace") != null ? " -> " + testcase.SelectSingleNode(".//stack-trace").InnerText.Replace("\r", "").Replace("\n", "") : "";
                        errorMsg += "</pre>";
                        errorMsg = errorMsg == "<pre class='stack-trace'></pre>" ? "" : errorMsg;
                    }
                    if (_consoleOutput.ContainsKey(tcAssemblyName) && !String.IsNullOrWhiteSpace(_consoleOutput[tcAssemblyName]))
                    {
                        tc.ConsoleLogs = String.Format(@"
                             <div id='{1}' class='modal'>
                                <div class='modal-content'>
                                    <h4>{2}</h4>
                                    {0}
                                </div>
                                <div class='modal-footer'>
                                    <a href='#!' class='modal-action modal-close waves-effect waves-green btn-flat'>Close</a>
                                </div>
                            </div>
                            <a class='modal-trigger waves-effect waves-light console-logs-icon tooltipped' data-position='left' data-tooltip='Console Logs' href='#{1}'><i class='mdi-action-assignment'></i></a>
                            ", _consoleOutput[tcAssemblyName], tcAssemblyName.Replace(".","_"), tcAssemblyName);
                    }

                    XmlNode desc = testcase.SelectSingleNode(".//property[@name='Description']");

                    if (desc != null)
                    {
                        descMsg += "<p class='description'>Description: " + desc.Attributes["value"].InnerText.Trim();
                        descMsg += "</p>";
                        descMsg = descMsg == "<p class='description'>Description: </p>" ? "" : descMsg;
                    }

                    tc.StatusMessage = descMsg + errorMsg;
                    testSuite.Tests.Add(tc);

                    Console.Write("\r{0} tests processed...", ++testCount);
                }

                testSuite.Status = ReportHelper.GetFixtureStatus(testSuite.Tests);

                _report.TestFixtures.Add(testSuite);
            }
        }
예제 #2
0
        private void ProcessFixtureBlocks()
        {
            Console.WriteLine("[INFO] Building fixture blocks...");

            string errorMsg = null;
            string descMsg = null;
            XmlNodeList suites = _doc.SelectNodes("//ns:testStep[@isTestCase='true']/ancestor::ns:testStepRun[2]", _nsmgr);
            int testCount = 0;

            // run for each test-suite
            foreach (XmlNode suite in suites)
            {
                var testSuite = new TestSuite();

                testSuite.Name = suite.SelectSingleNode("./ns:testStep", _nsmgr).Attributes["name"].InnerText;
                testSuite.StartTime = suite.Attributes["startTime"].InnerText.Split('.')[0];
                testSuite.EndTime = suite.Attributes["endTime"].InnerText.Split('.')[0];

                XmlNodeList tests = suite.SelectNodes("./ns:children/ns:testStepRun/ns:testStep[@isTestCase='true']", _nsmgr);

                foreach (XmlNode test in tests)
                {
                    errorMsg = descMsg = "";

                    var tc = new Test();
                    tc.Name = test.Attributes["name"].InnerText;
                    tc.Status = test.SelectSingleNode("./following-sibling::ns:result/ns:outcome/@status", _nsmgr).InnerText.AsStatus();

                    var category = test.SelectSingleNode("./ns:metadata/ns:entry[@key='Category']/ns:value", _nsmgr);

                    if (category != null)
                    {
                        tc.Categories.Add(category.InnerText);
                    }

                    var desc = test.SelectSingleNode("./ns:metadata/ns:entry[@key='Description']/ns:value", _nsmgr);

                    if (desc != null)
                    {
                        descMsg += "<p class='description'>Description: " + desc.InnerText.Trim();
                        descMsg += "</p>";
                        descMsg = descMsg == "<p class='description'>Description: </p>" ? "" : descMsg;
                    }

                    var testStepRun = test.ParentNode.SelectSingleNode(".//ns:testLog", _nsmgr);

                    if (testStepRun != null && testStepRun.InnerText.Trim() != "")
                        errorMsg = "<pre>" + testStepRun.InnerText + "</pre>";

                    tc.StatusMessage = descMsg + errorMsg;

                    testSuite.Tests.Add(tc);

                    Console.Write("\r{0} tests processed...", ++testCount);
                }

                testSuite.Status = ReportHelper.GetFixtureStatus(testSuite.Tests);

                _report.TestFixtures.Add(testSuite);
            }
        }
예제 #3
0
        /// <summary>
        /// Processes the tests level blocks
        /// Adds all tests to the output
        /// </summary>
        private void ProcessFixtureBlocks()
        {
            Console.WriteLine("[INFO] Building fixture blocks...");

            int testCount = 0;
            var unitTestResults = _doc.SelectNodes("descendant::t:UnitTestResult", _nsmgr);

            // run for each test-suite
            foreach (XmlNode testResult in unitTestResults)
            {

                Test tc = new Test();
                tc.Name = testResult.Attributes["testName"].InnerText;
                tc.Status = testResult.Attributes["outcome"].InnerText.AsStatus();

                try
                {
                    TimeSpan d;
                    var durationTimeSpan = testResult.Attributes["duration"].InnerText;
                    if (TimeSpan.TryParse(durationTimeSpan, out d))
                    {
                        tc.Duration = d.TotalMilliseconds;
                    }
                }
                catch (Exception)
                {
                    tc.Duration = DateTimeHelper.DifferenceInMilliseconds(testResult.Attributes["startTime"].InnerText, testResult.Attributes["endTime"].InnerText);
                }

                // check for any errors or messages
                if (testResult.HasChildNodes)
                {
                    string errorMsg = "", descMsg = "";
                    foreach (XmlNode node in testResult.ChildNodes)
                    {
                        if (node.Name.Equals("Output", StringComparison.CurrentCultureIgnoreCase) && node.HasChildNodes)
                        {
                            foreach (XmlNode msgNode in node.ChildNodes)
                            {
                                if (msgNode.Name.Equals("ErrorInfo", StringComparison.CurrentCultureIgnoreCase) && msgNode.HasChildNodes)
                                {
                                    errorMsg = msgNode["Message"] != null ? "<pre>" + msgNode["Message"].InnerText : "";
                                    errorMsg += msgNode["StackTrace"] != null ? msgNode["StackTrace"].InnerText.Replace("\r", "").Replace("\n", "") : "";
                                    errorMsg += "</pre>";
                                    errorMsg = errorMsg == "<pre></pre>" ? "" : errorMsg;
                                }
                                else if (msgNode.Name.Equals("StdOut", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    descMsg += "<p class='description'>Description: " + msgNode.InnerText;
                                    descMsg += "</p>";
                                    descMsg = descMsg == "<p class='description'>Description: </p>" ? "" : descMsg;
                                }
                            }
                        }
                    }
                    tc.StatusMessage = descMsg + errorMsg;
                }

                // get test details and fixture
                string testId = testResult.Attributes["testId"].InnerText;
                var testDefinition = _doc.SelectSingleNode("descendant::t:UnitTest[@id='" + testId + "']/t:TestMethod", _nsmgr);
                var className = testDefinition.Attributes["className"].InnerText;

                // get the test fixture details
                var testFixture = _report.TestFixtures.SingleOrDefault(f => f.Name.Equals(className, StringComparison.CurrentCultureIgnoreCase));
                if (testFixture == null)
                {
                    testFixture = new TestSuite();
                    testFixture.Name = className;

                    _report.TestFixtures.Add(testFixture);
                }

                // update test fixture with details from the test
                testFixture.Duration += tc.Duration;
                testFixture.Status = ReportHelper.GetFixtureStatus(new List<Status> { testFixture.Status, tc.Status });
                testFixture.Tests.Add(tc);

                Console.Write("\r{0} tests processed...", ++testCount);
            }
        }
예제 #4
0
        /// <summary>
        /// Processes the fixture level blocks
        /// Adds all tests to the output
        /// </summary>
        private void ProcessFixtureBlocks()
        {
            Console.WriteLine("[INFO] Building fixture blocks...");

            string errorMsg = null;
            string descMsg = null;
            XmlNodeList collectionNodes = _doc.SelectNodes(".//collection");
            int testCount = 0;

            // run for each test collection
            foreach (XmlNode suite in collectionNodes)
            {
                var testSuite = new TestSuite();
                testSuite.Name = suite.Attributes["name"].InnerText.Replace("Test collection for", "").Replace(_fileNameWithoutExtension + ".", "").Trim();

                if (suite.Attributes["time"] != null)
                {
                    double duration;
                    if (double.TryParse(suite.Attributes["time"].InnerText, out duration))
                    {
                        testSuite.Duration = duration;
                        testSuite.StartTime = duration.ToString();
                    }
                }

                // check if the testSuite has any errors (ie error in the TestFixtureSetUp)
                /*var testSuiteFailureNode = suite.SelectSingleNode("failure");
                if (testSuiteFailureNode != null && testSuiteFailureNode.HasChildNodes)
                {
                    errorMsg = descMsg = "";
                    var message = testSuiteFailureNode.SelectSingleNode(".//message");

                    if (message != null)
                    {
                        errorMsg = message.InnerText.Trim();
                        errorMsg += testSuiteFailureNode.SelectSingleNode(".//stack-trace") != null ? " -> " + testSuiteFailureNode.SelectSingleNode(".//stack-trace").InnerText.Replace("\r", "").Replace("\n", "") : "";
                    }
                    testSuite.StatusMessage = errorMsg;
                }*/

                // add each test of the test-fixture
                foreach (XmlNode testcase in suite.SelectNodes(".//test"))
                {
                    errorMsg = descMsg = "";

                    var tc = new Test();
                    tc.Name = testcase.Attributes["name"].InnerText.Replace(_fileNameWithoutExtension + ".", "").Replace(testSuite.Name + ".", "");
                    tc.Status = testcase.Attributes["result"].InnerText.AsStatus();

                    if (testcase.Attributes["time"] != null)
                    {
                        try
                        {
                            Double d;
                            var durationTimeSpan = testcase.Attributes["time"].InnerText;
                            if (Double.TryParse(durationTimeSpan, out d))
                            {
                                tc.Duration = d;
                            }
                        }
                        catch (Exception) { }
                    }

                    /*var categories = testcase.SelectNodes(".//property[@name='Category']");
                    foreach (XmlNode category in categories)
                    {
                        tc.Categories.Add(category.Attributes["value"].InnerText);
                    }*/

                    var message = testcase.SelectSingleNode(".//message");

                    if (message != null)
                    {
                        errorMsg = "<pre>";// + message.InnerText.Trim();
                        errorMsg += testcase.SelectSingleNode(".//stack-trace") != null ? " -> " + testcase.SelectSingleNode(".//stack-trace").InnerText.Replace("\r", "") : "";
                        errorMsg += "</pre>";
                        errorMsg = errorMsg == "<pre></pre>" ? "" : errorMsg;
                    }

                    /*XmlNode desc = testcase.SelectSingleNode(".//property[@name='Description']");

                    if (desc != null)
                    {
                        descMsg += "<p class='description'>Description: " + desc.Attributes["value"].InnerText.Trim();
                        descMsg += "</p>";
                        descMsg = descMsg == "<p class='description'>Description: </p>" ? "" : descMsg;
                    }*/

                    tc.StatusMessage = descMsg + errorMsg;
                    testSuite.Tests.Add(tc);

                    Console.Write("\r{0} tests processed...", ++testCount);
                }

                testSuite.Status = ReportHelper.GetFixtureStatus(testSuite.Tests);

                _report.TestFixtures.Add(testSuite);
            }
        }
예제 #5
0
        /// <summary>
        /// Processes the fixture level blocks
        /// Adds all tests to the output
        /// </summary>
        private void ProcessFixtureBlocks()
        {
            Console.WriteLine("[INFO] Building fixture blocks...");

            XmlNodeList testSuiteNodes = _doc.SelectNodes("//test-suite[@type='TestFixture']");
            int testCount = 0;

            // run for each test-suite
            foreach (XmlNode suite in testSuiteNodes)
            {
                var testSuite = new TestSuite
                {
                    Name = suite.Attributes["name"].InnerText,
                    Passed = suite.SelectNodes(".//test-case[@result='Success' or @result='Passed']").Count,
                    Failed = suite.SelectNodes(".//test-case[@result='Failed' or @result='Failure']").Count,
                    Inconclusive = suite.SelectNodes(".//test-case[@result='Inconclusive' or @result='NotRunnable']").Count,
                    Skipped = suite.SelectNodes(".//test-case[@result='Skipped' or @result='Ignored']").Count,
                    Errors = suite.SelectNodes(".//test-case[@result='Error']").Count,
                    Total = suite.SelectNodes(".//test-case").Count
                };

                if (suite.Attributes["start-time"] != null && suite.Attributes["end-time"] != null)
                {
                    var startTime = suite.Attributes["start-time"].InnerText.Replace("Z", "");
                    var endTime = suite.Attributes["end-time"].InnerText.Replace("Z", "");

                    testSuite.StartTime = startTime;
                    testSuite.EndTime = endTime;
                    testSuite.Duration = DateTimeHelper.DifferenceInMilliseconds(startTime, endTime);
                }
                else if (suite.Attributes["time"] != null)
                {
                    double duration;
                    if (double.TryParse(suite.Attributes["time"].InnerText.Replace("Z", ""), out duration))
                    {
                        testSuite.Duration = duration;
                    }

                    testSuite.StartTime = duration.ToString();
                }

                // check if the testSuite has any errors (ie error in the TestFixtureSetUp)
                var testSuiteFailureNode = suite.SelectSingleNode("failure");
                string errorMsg;
                string descMsg;
                if (testSuiteFailureNode != null && testSuiteFailureNode.HasChildNodes)
                {
                    errorMsg = descMsg = "";
                    var message = testSuiteFailureNode.SelectSingleNode(".//message");

                    if (message != null)
                    {
                        errorMsg = message.InnerText.Trim();
                        errorMsg += testSuiteFailureNode.SelectSingleNode(".//stack-trace") != null ? " -> " + testSuiteFailureNode.SelectSingleNode(".//stack-trace").InnerText.Replace("\r", "").Replace("\n", "") : "";
                    }
                    testSuite.StatusMessage = errorMsg;
                }

                // add each test of the test-fixture
                foreach (XmlNode testcase in suite.SelectNodes(".//test-case"))
                {
                    errorMsg = descMsg = "";

                    var tc = new Test
                    {
                        Name = testcase.Attributes["name"].InnerText.Replace("<", "[").Replace(">", "]"),
                        Status = testcase.Attributes["result"].InnerText.AsStatus()
                    };

                    if (testcase.Attributes["time"] != null)
                    {
                        try
                        {
                            TimeSpan d;
                            var durationTimeSpan = testcase.Attributes["duration"].InnerText;
                            if (TimeSpan.TryParse(durationTimeSpan, out d))
                            {
                                tc.Duration = d.TotalMilliseconds;
                            }
                        }
                        catch (Exception) { }
                    }

                    var categories = testcase.SelectNodes(".//property[@name='Category']");

                    foreach (XmlNode category in categories)
                    {
                        tc.Categories.Add(category.Attributes["value"].InnerText);
                    }

                    var message = testcase.SelectSingleNode(".//message");

                    if (message != null)
                    {
                        errorMsg = "<pre>" + message.InnerText.Trim();
                        errorMsg += testcase.SelectSingleNode(".//stack-trace") != null ? " -> " + testcase.SelectSingleNode(".//stack-trace").InnerText.Replace("\r", "").Replace("\n", "") : "";
                        errorMsg += "</pre>";
                        errorMsg = errorMsg == "<pre></pre>" ? "" : errorMsg;
                    }

                    XmlNode desc = testcase.SelectSingleNode(".//property[@name='Description']");

                    if (desc != null)
                    {
                        descMsg += "<p class='description'>Description: " + desc.Attributes["value"].InnerText.Trim();
                        descMsg += "</p>";
                        descMsg = descMsg == "<p class='description'>Description: </p>" ? "" : descMsg;
                    }

                    tc.StatusMessage = descMsg + errorMsg;
                    testSuite.Tests.Add(tc);

                    Console.Write("\r{0} tests processed...", ++testCount);
                }

                testSuite.Status = ReportHelper.GetFixtureStatus(testSuite.Tests);

                _report.TestFixtures.Add(testSuite);
            }
        }
예제 #6
0
        private TestSuite GetCollectionForTest(XmlNode colNode, XmlNode testCaseNode)
        {
            // work otu the collection name
            String collectionName = null;

            if (testCaseNode.Attributes["type"] != null)
            {
                collectionName = testCaseNode.Attributes["type"].InnerText.Replace(_fileNameWithoutExtension + ".", "");
            }
            if (string.IsNullOrWhiteSpace(collectionName) && colNode.Attributes["name"] != null)
            {
                collectionName = colNode.Attributes["name"].InnerText
                    .Replace("Test collection for", "")
                    .Replace("xUnit.net v1 Tests for", "")
                    .Replace(_assemblyFolder, "")
                    .Trim();
            }
            if (string.IsNullOrWhiteSpace(collectionName))
            {
                collectionName = _fileNameWithoutExtension;
            }

            // check if the collection exists
            TestSuite testCollection = _report.TestFixtures.FirstOrDefault(c => String.Equals(c.Name, collectionName));
            if (testCollection == null)
            {
                testCollection = new TestSuite();
                testCollection.Name = collectionName;

                _report.TestFixtures.Add(testCollection);
            }

            if (colNode.Attributes != null && colNode.Attributes.Count > 0)
            {
                // in xunit v1 xml reports - often have only one collection
                testCollection = _report.TestFixtures.FirstOrDefault(tf => string.IsNullOrWhiteSpace(tf.Name)) ?? new TestSuite();

                if (colNode.Attributes["time"] != null)
                {
                    double duration;
                    if (double.TryParse(colNode.Attributes["time"].InnerText, out duration))
                    {
                        testCollection.Duration = duration;
                        testCollection.StartTime = duration.ToString();
                    }
                }
            }

            return testCollection;
        }