Ejemplo n.º 1
0
        Xunit1RunSummary RunTestCollection(ITestCollection testCollection, IEnumerable <ITestCase> testCases, IMessageSink messageSink)
        {
            var results = new Xunit1RunSummary();

            results.Continue = messageSink.OnMessage(new TestCollectionStarting(testCases, testCollection));

            try
            {
                if (results.Continue)
                {
                    foreach (var testClassGroup in testCases.GroupBy(tc => tc.TestMethod.TestClass, Comparer.Instance))
                    {
                        var classResults = RunTestClass(testClassGroup.Key, testClassGroup.ToList(), messageSink);
                        results.Aggregate(classResults);
                        if (!classResults.Continue)
                        {
                            break;
                        }
                    }
                }
            }
            finally
            {
                results.Continue = messageSink.OnMessage(new TestCollectionFinished(testCases, testCollection, results.Time, results.Total, results.Failed, results.Skipped)) && results.Continue;
            }

            return(results);
        }
Ejemplo n.º 2
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));
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestClassCallbackHandler" /> class.
        /// </summary>
        /// <param name="testCases">The test cases that are being run.</param>
        /// <param name="messageSink">The message sink to call with the translated results.</param>
        public TestClassCallbackHandler(IList<ITestCase> testCases, IMessageSink messageSink)
            : base(lastNodeName: "class")
        {
            this.messageSink = messageSink;
            this.testCases = testCases;

            handlers = new Dictionary<string, Predicate<XmlNode>> { { "class", OnClass }, { "start", OnStart }, { "test", OnTest } };

            TestClassResults = new Xunit1RunSummary();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestClassCallbackHandler" /> class.
        /// </summary>
        /// <param name="testCases">The test cases that are being run.</param>
        /// <param name="messageSink">The message sink to call with the translated results.</param>
        public TestClassCallbackHandler(IList <ITestCase> testCases, IMessageSink messageSink)
            : base(lastNodeName: "class")
        {
            this.messageSink = messageSink;
            this.testCases   = testCases;

            handlers = new Dictionary <string, Predicate <XmlNode> > {
                { "class", OnClass }, { "start", OnStart }, { "test", OnTest }
            };

            TestClassResults = new Xunit1RunSummary();
        }