示例#1
0
        bool OnClass(XmlNode xml)
        {
            SendTestCaseMessagesWhenAppropriate(null);

            var     @continue = true;
            XmlNode failureNode;

            if ((failureNode = xml.SelectSingleNode("failure")) != null)
            {
                var failureInformation = Xunit1ExceptionUtility.ConvertToFailureInformation(failureNode);

                var errorMessage = new ErrorMessage(testCases,
                                                    failureInformation.ExceptionTypes,
                                                    failureInformation.Messages,
                                                    failureInformation.StackTraces,
                                                    failureInformation.ExceptionParentIndices);
                @continue = messageSink.OnMessage(errorMessage);
            }

            TestClassResults.Time    = decimal.Parse(xml.Attributes["time"].Value, CultureInfo.InvariantCulture);
            TestClassResults.Total   = int.Parse(xml.Attributes["total"].Value, CultureInfo.InvariantCulture);
            TestClassResults.Failed  = int.Parse(xml.Attributes["failed"].Value, CultureInfo.InvariantCulture);
            TestClassResults.Skipped = int.Parse(xml.Attributes["skipped"].Value, CultureInfo.InvariantCulture);
            return(@continue && TestClassResults.Continue);
        }
示例#2
0
        RunSummary RunTestClass(ITestCollection testCollection, string className, IList <Xunit1TestCase> testCases, IMessageSink messageSink)
        {
            var handler = new TestClassCallbackHandler(testCases, messageSink);
            var results = handler.TestClassResults;

            results.Continue = messageSink.OnMessage(new TestClassStarting(testCollection, className));

            if (results.Continue)
            {
                try
                {
                    var methodNames = testCases.Select(tc => tc.Method.Name).ToList();
                    executor.RunTests(className, methodNames, handler);
                    handler.LastNodeArrived.WaitOne();
                }
                catch (Exception ex)
                {
                    var failureInformation = Xunit1ExceptionUtility.ConvertToFailureInformation(ex);

                    results.Continue = messageSink.OnMessage(new ErrorMessage(failureInformation.ExceptionTypes, failureInformation.Messages, failureInformation.StackTraces, failureInformation.ExceptionParentIndices)) && results.Continue;
                }
            }

            results.Continue = messageSink.OnMessage(new TestClassFinished(testCollection, className, results.Time, results.Total, results.Failed, results.Skipped)) && results.Continue;
            return(results);
        }
示例#3
0
        /// <summary>
        /// Starts the process of running all the xUnit.net v1 tests.
        /// </summary>
        /// <param name="testCases">The test cases to run; if null, all tests in the assembly are run.</param>
        /// <param name="messageSink">The message sink to report results back to.</param>
        public void Run(IEnumerable <ITestCase> testCases, IMessageSink messageSink)
        {
            var results        = new Xunit1RunSummary();
            var environment    = String.Format("{0}-bit .NET {1}", IntPtr.Size * 8, Environment.Version);
            var firstTestCase  = testCases.FirstOrDefault();
            var testCollection = firstTestCase == null ? null : firstTestCase.TestMethod.TestClass.TestCollection;

            if (testCollection != null)
            {
                try
                {
                    if (messageSink.OnMessage(new TestAssemblyStarting(testCases, testCollection.TestAssembly, DateTime.Now, environment, TestFrameworkDisplayName)))
                    {
                        results = RunTestCollection(testCollection, testCases, messageSink);
                    }
                }
                catch (Exception ex)
                {
                    var failureInformation = Xunit1ExceptionUtility.ConvertToFailureInformation(ex);

                    messageSink.OnMessage(new ErrorMessage(testCases, failureInformation.ExceptionTypes,
                                                           failureInformation.Messages, failureInformation.StackTraces,
                                                           failureInformation.ExceptionParentIndices));
                }
                finally
                {
                    messageSink.OnMessage(new TestAssemblyFinished(testCases, testCollection.TestAssembly, results.Time, results.Total, results.Failed, results.Skipped));
                }
            }
        }
示例#4
0
        bool OnTest(XmlNode xml)
        {
            var @continue     = true;
            var testCase      = FindTestCase(xml.Attributes["type"].Value, xml.Attributes["method"].Value);
            var timeAttribute = xml.Attributes["time"];
            var time          = timeAttribute == null ? 0M : Decimal.Parse(timeAttribute.Value, CultureInfo.InvariantCulture);
            var outputElement = xml.SelectSingleNode("output");
            var output        = outputElement == null ? String.Empty : outputElement.InnerText;
            var displayName   = xml.Attributes["name"].Value;
            ITestCaseMessage resultMessage = null;

            testCaseResults.Total++;
            testCaseResults.Time += time;

            switch (xml.Attributes["result"].Value)
            {
            case "Pass":
                resultMessage = new TestPassed(testCase, displayName, time, output);
                break;

            case "Fail":
            {
                testCaseResults.Failed++;
                var failure            = xml.SelectSingleNode("failure");
                var failureInformation = Xunit1ExceptionUtility.ConvertToFailureInformation(failure);
                resultMessage = new TestFailed(testCase, displayName, time, output,
                                               failureInformation.ExceptionTypes,
                                               failureInformation.Messages,
                                               failureInformation.StackTraces,
                                               failureInformation.ExceptionParentIndices);
                break;
            }

            case "Skip":
                testCaseResults.Skipped++;
                if (testCase != lastTestCase)
                {
                    SendTestCaseMessagesWhenAppropriate(testCase);
                    @continue = messageSink.OnMessage(new TestStarting(testCase, displayName)) && @continue;
                }
                resultMessage = new TestSkipped(testCase, displayName, xml.SelectSingleNode("reason/message").InnerText);
                break;
            }

            if (resultMessage != null)
            {
                @continue = messageSink.OnMessage(resultMessage) && @continue;
            }

            @continue = messageSink.OnMessage(new TestFinished(testCase, displayName, time, output)) && @continue;
            return(@continue && TestClassResults.Continue);
        }
示例#5
0
        bool OnTest(XmlNode xml)
        {
            var @continue     = true;
            var testCase      = FindTestCase(xml.Attributes["type"].Value, xml.Attributes["method"].Value);
            var timeAttribute = xml.Attributes["time"];
            var time          = timeAttribute == null ? 0M : decimal.Parse(timeAttribute.Value, CultureInfo.InvariantCulture);
            var outputElement = xml.SelectSingleNode("output");
            var output        = outputElement == null ? string.Empty : outputElement.InnerText;
            ITestCaseMessage resultMessage = null;

            if (currentTest == null)  // There is no <start> node for skipped tests, or with xUnit prior to v1.1
            {
                currentTest = new Xunit1Test(testCase, xml.Attributes["name"].Value);
            }

            testCaseResults.Total++;
            testCaseResults.Time += time;

            switch (xml.Attributes["result"].Value)
            {
            case "Pass":
                resultMessage = new TestPassed(currentTest, time, output);
                break;

            case "Fail":
            {
                testCaseResults.Failed++;
                var failure            = xml.SelectSingleNode("failure");
                var failureInformation = Xunit1ExceptionUtility.ConvertToFailureInformation(failure);
                resultMessage = new TestFailed(currentTest, time, output,
                                               failureInformation.ExceptionTypes,
                                               failureInformation.Messages,
                                               failureInformation.StackTraces,
                                               failureInformation.ExceptionParentIndices);
                break;
            }

            case "Skip":
                testCaseResults.Skipped++;
                if (testCase != lastTestCase)
                {
                    SendTestCaseMessagesWhenAppropriate(testCase);
                    @continue = messageSink.OnMessage(new TestStarting(currentTest)) && @continue;
                }
                resultMessage = new TestSkipped(currentTest, xml.SelectSingleNode("reason/message").InnerText);
                break;
            }

            // Since we don't get live output from xUnit.net v1, we just send a single output message just before
            // the result message (if there was any output).
            if (!string.IsNullOrEmpty(output))
            {
                @continue = messageSink.OnMessage(new TestOutput(currentTest, output)) && @continue;
            }

            if (resultMessage != null)
            {
                @continue = messageSink.OnMessage(resultMessage) && @continue;
            }

            @continue   = messageSink.OnMessage(new TestFinished(currentTest, time, output)) && @continue;
            currentTest = null;

            return(@continue && TestClassResults.Continue);
        }