コード例 #1
0
        /// <summary>
        /// Gets the test framework object for the given test assembly. It is important that callers to this function have
        /// called <see cref="TestContext.SetForInitialization"/> before calling this, so that the test framework and
        /// any ancillary helper classes have access to the diagnostic and internal diagnostic message sinks.
        /// </summary>
        /// <param name="testAssembly">The test assembly to get the test framework for</param>
        /// <returns>The test framework object</returns>
        public static _ITestFramework GetTestFramework(_IAssemblyInfo testAssembly)
        {
            _ITestFramework result;

            var testFrameworkType = GetTestFrameworkType(testAssembly);

            if (!typeof(_ITestFramework).IsAssignableFrom(testFrameworkType))
            {
                TestContext.Current?.SendDiagnosticMessage("Test framework type '{0}' does not implement '{1}'; falling back to '{2}'", testFrameworkType.FullName, typeof(_ITestFramework).FullName, typeof(XunitTestFramework).FullName);

                testFrameworkType = typeof(XunitTestFramework);
            }

            try
            {
                result = (_ITestFramework)Activator.CreateInstance(testFrameworkType) !;
            }
            catch (Exception ex)
            {
                TestContext.Current?.SendDiagnosticMessage("Exception thrown during test framework construction; falling back to default test framework: {0}", ex.Unwrap());

                result = new XunitTestFramework();
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestFrameworkProxy"/> class.
        /// </summary>
        /// <param name="testAssemblyObject">The test assembly (expected to implement <see cref="IAssemblyInfo"/>).</param>
        /// <param name="sourceInformationProviderObject">The source information provider (expected to implement <see cref="ISourceInformationProvider"/>).</param>
        public TestFrameworkProxy(object testAssemblyObject, object sourceInformationProviderObject)
        {
#if PLATFORM_LINUX || PLATFORM_MACOS
            InnerTestFramework        = new XunitTestFramework();
            SourceInformationProvider = new NullMonoSourceInformationProvider();
#else
            var testAssembly = (IAssemblyInfo)testAssemblyObject;
            var sourceInformationProvider = (ISourceInformationProvider)sourceInformationProviderObject;

            var testFrameworkType = typeof(XunitTestFramework);

            try
            {
                var testFrameworkAttr = testAssembly.GetCustomAttributes(typeof(ITestFrameworkAttribute)).FirstOrDefault();
                if (testFrameworkAttr != null)
                {
                    var discovererAttr = testFrameworkAttr.GetCustomAttributes(typeof(TestFrameworkDiscovererAttribute)).FirstOrDefault();
                    if (discovererAttr != null)
                    {
                        var discoverer = ExtensibilityPointFactory.GetTestFrameworkTypeDiscoverer(discovererAttr);
                        if (discoverer != null)
                        {
                            testFrameworkType = discoverer.GetTestFrameworkType(testFrameworkAttr);
                        }
                        // else                     // TODO: Log environmental error
                    }
                    // else                     // TODO: Log environmental error
                }
            }
            catch
            {
                // TODO: Log environmental error
            }

            try
            {
                InnerTestFramework = (ITestFramework)Activator.CreateInstance(testFrameworkType);
            }
            catch
            {
                // TODO: Log environmental error
                InnerTestFramework = new XunitTestFramework();
            }

            SourceInformationProvider = sourceInformationProvider;
#endif
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TestFrameworkProxy"/> class.
        /// </summary>
        /// <param name="testAssemblyObject">The test assembly (expected to implement <see cref="IAssemblyInfo"/>).</param>
        /// <param name="sourceInformationProviderObject">The source information provider (expected to implement <see cref="ISourceInformationProvider"/>).</param>
        public TestFrameworkProxy(object testAssemblyObject, object sourceInformationProviderObject)
        {
            var testAssembly = (IAssemblyInfo)testAssemblyObject;
            var sourceInformationProvider = (ISourceInformationProvider)sourceInformationProviderObject;

            var testFrameworkType = typeof(XunitTestFramework);

            try
            {
                var testFrameworkAttr = testAssembly.GetCustomAttributes(typeof(ITestFrameworkAttribute)).FirstOrDefault();
                if (testFrameworkAttr != null)
                {
                    var discovererAttr = testFrameworkAttr.GetCustomAttributes(typeof(TestFrameworkDiscovererAttribute)).FirstOrDefault();
                    if (discovererAttr != null)
                    {
                        var discoverer = ExtensibilityPointFactory.GetTestFrameworkTypeDiscoverer(discovererAttr);
                        if (discoverer != null)
                            testFrameworkType = discoverer.GetTestFrameworkType(testFrameworkAttr);
                        // else                     // TODO: Log environmental error
                    }
                    // else                     // TODO: Log environmental error
                }
            }
            catch
            {
                // TODO: Log environmental error
            }

            try
            {
                InnerTestFramework = (ITestFramework)Activator.CreateInstance(testFrameworkType);
            }
            catch
            {
                // TODO: Log environmental error
                InnerTestFramework = new XunitTestFramework();
            }

            SourceInformationProvider = sourceInformationProvider;
        }