示例#1
0
        /// <summary>
        /// Runs the specified test methods.
        /// </summary>
        /// <param name="testMethods">The test methods to run.</param>
        /// <param name="callback">The run status information callback.</param>
        /// <returns>Returns the result as XML.</returns>
        public virtual string Run(IEnumerable<TestMethod> testMethods, ITestMethodRunnerCallback callback)
        {
            Guard.ArgumentNotNullOrEmpty("testMethods", testMethods);
            Guard.ArgumentNotNull("callback", callback);

            var sortedMethods = new Dictionary<TestClass, List<TestMethod>>();

            foreach (TestClass testClass in testClasses)
                sortedMethods[testClass] = new List<TestMethod>();

            foreach (TestMethod testMethod in testMethods)
            {
                List<TestMethod> methodList = null;

                if (!sortedMethods.TryGetValue(testMethod.TestClass, out methodList))
                    throw new ArgumentException("Test method " + testMethod.MethodName +
                                                " on test class " + testMethod.TestClass.TypeName +
                                                " is not in this assembly", "testMethods");

                methodList.Add(testMethod);
            }

            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<assembly/>");
            XmlNode assemblyNode = doc.ChildNodes[0];

            AddAttribute(assemblyNode, "name", ExecutorWrapper.AssemblyFilename);
            AddAttribute(assemblyNode, "run-date", DateTime.Now.ToString("yyyy-MM-dd"));
            AddAttribute(assemblyNode, "run-time", DateTime.Now.ToString("HH:mm:ss"));
            if (ExecutorWrapper.ConfigFilename != null)
                AddAttribute(assemblyNode, "configFile", ExecutorWrapper.ConfigFilename);

            callback.AssemblyStart(this);

            var callbackWrapper = new TestMethodRunnerCallbackWrapper(callback);

            int passed = 0;
            int failed = 0;
            int skipped = 0;
            double duration = 0.0;
            string result = "";

            foreach (var kvp in sortedMethods)
                if (kvp.Value.Count > 0)
                {
                    result += kvp.Key.Run(kvp.Value, callbackWrapper);

                    foreach (TestMethod testMethod in kvp.Value)
                        foreach (TestResult runResult in testMethod.RunResults)
                        {
                            duration += runResult.Duration;

                            if (runResult is TestPassedResult)
                                passed++;
                            else if (runResult is TestFailedResult)
                                failed++;
                            else
                                skipped++;
                        }
                }

            callback.AssemblyFinished(this, callbackWrapper.Total, callbackWrapper.Failed,
                                      callbackWrapper.Skipped, callbackWrapper.Time);

            AddAttribute(assemblyNode, "time", duration.ToString("0.000", CultureInfo.InvariantCulture));
            AddAttribute(assemblyNode, "total", passed + failed + skipped);
            AddAttribute(assemblyNode, "passed", passed);
            AddAttribute(assemblyNode, "failed", failed);
            AddAttribute(assemblyNode, "skipped", skipped);
            AddAttribute(assemblyNode, "environment", String.Format("{0}-bit .NET {1}", IntPtr.Size * 8, Environment.Version));
            AddAttribute(assemblyNode, "test-framework", String.Format("xUnit.net {0}", ExecutorWrapper.XunitVersion));

            return assemblyNode.OuterXml.Replace(" />", ">") + result + "</assembly>";
        }
 /// <inheritdoc/>
 public void AssemblyFinished(string assemblyFilename, int total, int failed, int skipped, double time)
 {
     callback.AssemblyFinished(testClass.TestAssembly, total, failed, skipped, time);
 }
示例#3
0
        /// <inheritdoc/>
        public virtual void Run(IEnumerable<TestMethod> testMethods, ITestMethodRunnerCallback callback)
        {
            Guard.ArgumentNotNullOrEmpty("testMethods", testMethods);
            Guard.ArgumentNotNull("callback", callback);

            var sortedMethods = new Dictionary<TestClass, List<TestMethod>>();

            foreach (TestClass testClass in testClasses)
                sortedMethods[testClass] = new List<TestMethod>();

            foreach (TestMethod testMethod in testMethods)
            {
                List<TestMethod> methodList = null;

                if (!sortedMethods.TryGetValue(testMethod.TestClass, out methodList))
                    throw new ArgumentException("Test method " + testMethod.MethodName +
                                                " on test class " + testMethod.TestClass.TypeName +
                                                " is not in this assembly", "testMethods");

                methodList.Add(testMethod);
            }

            callback.AssemblyStart(this);

            var callbackWrapper = new TestMethodRunnerCallbackWrapper(callback);

            foreach (var kvp in sortedMethods)
                if (kvp.Value.Count > 0)
                    kvp.Key.Run(kvp.Value, callbackWrapper);

            callback.AssemblyFinished(this, callbackWrapper.Total, callbackWrapper.Failed,
                                      callbackWrapper.Skipped, callbackWrapper.Time);
        }
示例#4
0
        /// <summary>
        /// Runs the specified test methods.
        /// </summary>
        /// <param name="testMethods">The test methods to run.</param>
        /// <param name="callback">The run status information callback.</param>
        /// <returns>Returns the result as XML.</returns>
        public virtual string Run(IEnumerable <TestMethod> testMethods, ITestMethodRunnerCallback callback)
        {
            Guard.ArgumentNotNullOrEmpty("testMethods", testMethods);
            Guard.ArgumentNotNull("callback", callback);

            var sortedMethods = new Dictionary <TestClass, List <TestMethod> >();

            foreach (TestClass testClass in testClasses)
            {
                sortedMethods[testClass] = new List <TestMethod>();
            }

            foreach (TestMethod testMethod in testMethods)
            {
                List <TestMethod> methodList = null;

                if (!sortedMethods.TryGetValue(testMethod.TestClass, out methodList))
                {
                    throw new ArgumentException("Test method " + testMethod.MethodName +
                                                " on test class " + testMethod.TestClass.TypeName +
                                                " is not in this assembly", "testMethods");
                }

                methodList.Add(testMethod);
            }

            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<assembly/>");
            XmlNode assemblyNode = doc.ChildNodes[0];

            AddAttribute(assemblyNode, "name", ExecutorWrapper.AssemblyFilename);
            AddAttribute(assemblyNode, "run-date", DateTime.Now.ToString("yyyy-MM-dd"));
            AddAttribute(assemblyNode, "run-time", DateTime.Now.ToString("HH:mm:ss"));
            if (ExecutorWrapper.ConfigFilename != null)
            {
                AddAttribute(assemblyNode, "configFile", ExecutorWrapper.ConfigFilename);
            }

            callback.AssemblyStart(this);

            var callbackWrapper = new TestMethodRunnerCallbackWrapper(callback);

            int    passed   = 0;
            int    failed   = 0;
            int    skipped  = 0;
            double duration = 0.0;
            string result   = "";

            foreach (var kvp in sortedMethods)
            {
                if (kvp.Value.Count > 0)
                {
                    result += kvp.Key.Run(kvp.Value, callbackWrapper);

                    foreach (TestMethod testMethod in kvp.Value)
                    {
                        foreach (TestResult runResult in testMethod.RunResults)
                        {
                            duration += runResult.Duration;

                            if (runResult is TestPassedResult)
                            {
                                passed++;
                            }
                            else if (runResult is TestFailedResult)
                            {
                                failed++;
                            }
                            else
                            {
                                skipped++;
                            }
                        }
                    }
                }
            }

            callback.AssemblyFinished(this, callbackWrapper.Total, callbackWrapper.Failed,
                                      callbackWrapper.Skipped, callbackWrapper.Time);

            AddAttribute(assemblyNode, "time", duration.ToString("0.000", CultureInfo.InvariantCulture));
            AddAttribute(assemblyNode, "total", passed + failed + skipped);
            AddAttribute(assemblyNode, "passed", passed);
            AddAttribute(assemblyNode, "failed", failed);
            AddAttribute(assemblyNode, "skipped", skipped);
            AddAttribute(assemblyNode, "environment", String.Format("{0}-bit .NET {1}", IntPtr.Size * 8, Environment.Version));
            AddAttribute(assemblyNode, "test-framework", String.Format("xUnit.net {0}", ExecutorWrapper.XunitVersion));

            return(assemblyNode.OuterXml.Replace(" />", ">") + result + "</assembly>");
        }