TestClass.cs :  » Testing » xUnit.net » Xunit » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Testing » xUnit.net 
xUnit.net » Xunit » TestClass.cs
using System;
using System.Collections.Generic;
using Xunit.Sdk;

namespace Xunit{
    /// <summary>
    /// Represents a single class with test methods.
    /// </summary>
    public class TestClass : ITestMethodEnumerator, ITestMethodRunner
    {
        IEnumerable<TestMethod> testMethods;

        /// <summary>
        /// Initializes a new instance of the <see cref="TestClass"/> class.
        /// </summary>
        /// <param name="typeName">The namespace-qualified type name that
        /// this class represents.</param>
        /// <param name="testMethods">The test methods inside this test class.</param>
        public TestClass(string typeName, IEnumerable<TestMethod> testMethods)
        {
            Guard.ArgumentNotNull("testMethods", testMethods);

            TypeName = typeName;
            this.testMethods = testMethods;

            foreach (TestMethod testMethod in testMethods)
                testMethod.TestClass = this;
        }

        /// <summary>
        /// Gets the test assembly that this class belongs to.
        /// </summary>
        public TestAssembly TestAssembly { get; internal set; }

        /// <summary>
        /// Gets the namespace-qualified type name of this class.
        /// </summary>
        public string TypeName { get; private set; }

        /// <inheritdoc/>
        public IEnumerable<TestMethod> EnumerateTestMethods()
        {
            return EnumerateTestMethods(m => true);
        }

        /// <inheritdoc/>
        public IEnumerable<TestMethod> EnumerateTestMethods(Predicate<TestMethod> filter)
        {
            Guard.ArgumentNotNull("filter", filter);

            foreach (TestMethod testMethod in testMethods)
                if (filter(testMethod))
                    yield return testMethod;
        }

        internal TestMethod GetMethod(string methodName)
        {
            foreach (TestMethod testMethod in testMethods)
                if (testMethod.MethodName == methodName)
                    return testMethod;

            throw new InvalidOperationException("Got callback for test method " + methodName +
                                                " outside the scope of running class " + TypeName);
        }

        /// <summary>
        /// Gets the test runner used to run tests. Exists as an overload primarily
        /// for the purposes of unit testing.
        /// </summary>
        /// <param name="callback">The run status information callback.</param>
        protected virtual ITestRunner GetTestRunner(ITestMethodRunnerCallback callback)
        {
            return new TestRunner(TestAssembly.ExecutorWrapper,
                                  new TestClassCallbackDispatcher(this, callback));
        }

        /// <inheritdoc/>
        public virtual void Run(IEnumerable<TestMethod> testMethods, ITestMethodRunnerCallback callback)
        {
            Guard.ArgumentNotNullOrEmpty("testMethods", testMethods);
            Guard.ArgumentNotNull("callback", callback);

            List<string> methodNames = new List<string>();

            foreach (TestMethod testMethod in testMethods)
            {
                if (testMethod.TestClass != this)
                    throw new ArgumentException("All test methods must belong to this test class");

                methodNames.Add(testMethod.MethodName);
                testMethod.RunResults.Clear();
            }

            GetTestRunner(callback).RunTests(TypeName, methodNames);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.