예제 #1
0
        private IList <Test> GetFixtures(Assembly assembly, IList names)
        {
            var fixtures  = new List <Test>();
            var testTypes = GetCandidateFixtureTypes(assembly, names);
            int testcases = 0;

            foreach (Type testType in testTypes)
            {
                var typeInfo = new TypeWrapper(testType);

                try
                {
                    if (_unitySuiteBuilder.CanBuildFrom(typeInfo))
                    {
                        Test fixture = _unitySuiteBuilder.BuildFrom(typeInfo);
                        fixtures.Add(fixture);
                        testcases += fixture.TestCaseCount;
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            }


            return(fixtures);
        }
예제 #2
0
        private IList GetFixtures(Assembly assembly, IList names)
        {
            var fixtures = new List <Test>();

            log.Debug("Examining assembly for test fixtures");

            IList testTypes = GetCandidateFixtureTypes(assembly, names);

            log.Debug("Found {0} classes to examine", testTypes.Count);
#if LOAD_TIMING
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
#endif
            int testcases = 0;
            foreach (Type testType in testTypes)
            {
                if (_defaultSuiteBuilder.CanBuildFrom(testType))
                {
                    Test fixture = _defaultSuiteBuilder.BuildFrom(testType);
                    fixtures.Add(fixture);
                    testcases += fixture.TestCaseCount;
                }
            }

#if LOAD_TIMING
            log.Debug("Found {0} fixtures with {1} test cases in {2} seconds", fixtures.Count, testcases, timer.Elapsed);
#else
            log.Debug("Found {0} fixtures with {1} test cases", fixtures.Count, testcases);
#endif

            return(fixtures);
        }
예제 #3
0
        /// <summary>
        /// Build a TestSuite from type provided.
        /// </summary>
        /// <param name="type">The type of the fixture to be used</param>
        /// <returns>A TestSuite</returns>
        public Test BuildFrom(Type type)
        {
            TestSuite suite = new LegacySuite(type);

            if (suite.RunState == RunState.NotRunnable)
            {
                string reason = null;
                if (!IsValidFixtureType(type, ref reason))
                {
                    suite.RunState = RunState.NotRunnable;
                    suite.Properties.Set(PropertyNames.SkipReason, reason);
                }
            }

            PropertyInfo suiteProperty = GetSuiteProperty(type);
            MethodInfo   method        = suiteProperty.GetGetMethod(true);

            if (method.GetParameters().Length > 0)
            {
                suite.RunState = RunState.NotRunnable;
                suite.Properties.Set(PropertyNames.SkipReason, "Suite property may not be indexed");
            }
            // TODO: Stop checking for name
            else if (method.ReturnType.FullName == "NUnit.Framework.Internal.TestSuite")
            {
                TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
                foreach (Test test in s.Tests)
                {
                    suite.Add(test);
                }
            }
            else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType))
            {
                foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0]))
                {
                    Type objType = obj as Type;
                    if (objType != null && _defaultSuiteBuilder.CanBuildFrom(objType))
                    {
                        suite.Add(_defaultSuiteBuilder.BuildFrom(objType));
                    }
                    else
                    {
                        var fixture = _defaultSuiteBuilder.BuildFrom(obj.GetType());
                        if (fixture != null)
                        {
                            fixture.Fixture = obj;
                        }
                        suite.Add(fixture);
                    }
                }
            }
            else
            {
                suite.RunState = RunState.NotRunnable;
                suite.Properties.Set(PropertyNames.SkipReason, "Suite property must return either TestSuite or IEnumerable");
            }

            return(suite);
        }
예제 #4
0
        private Test BuildSingleFixture(Type testType)
        {
            // The only place we currently allow legacy suites
            if (legacySuiteBuilder.CanBuildFrom(testType))
            {
                return(legacySuiteBuilder.BuildFrom(testType));
            }

            return(TestFixtureBuilder.BuildFrom(testType));
        }
예제 #5
0
 public bool CanBuildFrom(Type type)
 {
     TryLoadBuilder(type.Assembly);
     if (builder == null)
     {
         return(false);
     }
     else
     {
         return(builder.CanBuildFrom(type));
     }
 }
예제 #6
0
        public void CanAddSuiteBuilder()
        {
            ISuiteBuilder mockBuilder = Substitute.For <ISuiteBuilder>();

            mockBuilder.CanBuildFrom(Arg.Any <Type>()).Returns(true);

            IExtensionPoint ep = host.GetExtensionPoint("SuiteBuilders");

            ep.Install(mockBuilder);
            ISuiteBuilder builders = (ISuiteBuilder)ep;

            builders.BuildFrom(null);

            mockBuilder.Received().BuildFrom(null);
        }
예제 #7
0
 private Test Build(string assemblyName, Type testType, bool autoSuites)
 {
     // TODO: This is the only situation in which we currently
     // recognize and load legacy suites. We need to determine
     // whether to allow them in more places.
     if (legacySuiteBuilder.CanBuildFrom(testType))
     {
         return(legacySuiteBuilder.BuildFrom(testType));
     }
     else if (TestFixtureBuilder.CanBuildFrom(testType))
     {
         return(BuildTestAssembly(assemblyName,
                                  new Test[] { TestFixtureBuilder.BuildFrom(testType) }, autoSuites));
     }
     return(null);
 }
예제 #8
0
        private IList <Test> GetFixtures(Assembly assembly)
        {
            var fixtures = new List <Test>();

            log.Debug("Examining assembly for test fixtures");

            var testTypes = GetCandidateFixtureTypes(assembly);

            log.Debug("Found {0} classes to examine", testTypes.Count);
#if LOAD_TIMING
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();
#endif
            int testcases = 0;
            foreach (Type testType in testTypes)
            {
                var typeInfo = new TypeWrapper(testType);

                // Any exceptions from this call are fatal problems in NUnit itself,
                // since this is always DefaultSuiteBuilder and the current implementation
                // of DefaultSuiteBuilder.CanBuildFrom cannot invoke any user code.
                if (_defaultSuiteBuilder.CanBuildFrom(typeInfo))
                {
                    // We pass the filter for use in selecting methods of the type.
                    // Any exceptions from this call are fatal problems in NUnit itself,
                    // since this is always DefaultSuiteBuilder and the current implementation
                    // of DefaultSuiteBuilder.BuildFrom handles all exceptions from user code.
                    Test fixture = _defaultSuiteBuilder.BuildFrom(typeInfo, _filter);
                    fixtures.Add(fixture);
                    testcases += fixture.TestCaseCount;
                }
            }

#if LOAD_TIMING
            log.Debug("Found {0} fixtures with {1} test cases in {2} seconds", fixtures.Count, testcases, timer.Elapsed);
#else
            log.Debug("Found {0} fixtures with {1} test cases", fixtures.Count, testcases);
#endif

            return(fixtures);
        }
예제 #9
0
 public void CannotBuildFromNonGenericType()
 {
     Assert.That(!_suiteBuilder.CanBuildFrom(
                     typeof(NonGenericFixture)));
 }
예제 #10
0
 /// <summary>
 /// Determines whether this instance [can build from] the specified type.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <returns>
 ///     <c>true</c> if this instance [can build from] the specified type; otherwise, <c>false</c>.
 /// </returns>
 public static bool CanBuildFrom(Type type)
 {
     return(builder.CanBuildFrom(type));
 }