コード例 #1
0
        /// <summary>
        /// Build a suite based on a TestPackage
        /// </summary>
        /// <param name="package">The TestPackage</param>
        /// <returns>A TestSuite</returns>
        public TestSuite Build(TestPackage package)
        {
            bool autoNamespaceSuites = package.GetSetting("AutoNamespaceSuites", true);
            bool mergeAssemblies     = package.GetSetting("MergeAssemblies", false);

            if (package.IsSingleAssembly)
            {
                return(BuildSingleAssembly(package));
            }
            string targetAssemblyName = null;

            if (package.TestName != null && package.Assemblies.Contains(package.TestName))
            {
                targetAssemblyName = package.TestName;
                package.TestName   = null;
            }

            TestSuite            rootSuite     = new TestSuite(package.FullName);
            NamespaceTreeBuilder namespaceTree =
                new NamespaceTreeBuilder(rootSuite);

            builders.Clear();
            foreach (string assemblyName in package.Assemblies)
            {
                if (targetAssemblyName == null || targetAssemblyName == assemblyName)
                {
                    TestAssemblyBuilder builder = new TestAssemblyBuilder();
                    builders.Add(builder);

                    Test testAssembly = builder.Build(assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies);

                    if (testAssembly != null)
                    {
                        if (!mergeAssemblies)
                        {
                            rootSuite.Add(testAssembly);
                        }
                        else if (autoNamespaceSuites)
                        {
                            namespaceTree.Add(testAssembly.Tests);
                            rootSuite = namespaceTree.RootSuite;
                        }
                        else
                        {
                            foreach (Test test in testAssembly.Tests)
                            {
                                rootSuite.Add(test);
                            }
                        }
                    }
                }
            }

            if (rootSuite.Tests.Count == 0)
            {
                return(null);
            }

            return(rootSuite);
        }
コード例 #2
0
        public TestResult RunAllUnitTests(Action<string> callback, Assembly testAssembly = null)
        {
            if (testAssembly == null)
            {
                testAssembly = Assembly.GetCallingAssembly();
            }

            CoreExtensions.Host.InitializeService();
            TestExecutionContext.CurrentContext.TestPackage = new TestPackage(string.Format("TestPackage for {0}", testAssembly.GetName().FullName));

            var builder = new NamespaceTreeBuilder(new TestAssembly(testAssembly, testAssembly.GetName().FullName));
            var fixtures = testAssembly.GetTypes().Where(i => TestFixtureBuilder.CanBuildFrom(i)).Select(i => TestFixtureBuilder.BuildFrom(i)).ToList();

            builder.Add(fixtures);
            return builder.RootSuite.Run(new ConsoleListener(callback), TestFilter.Empty);
        }
コード例 #3
0
ファイル: PvcNUnit.cs プロジェクト: Buildstarted/pvc-nunit
        private void RunAllUnitTests(PvcStream stream)
        {
            Console.WriteLine("Testing: " + stream.OriginalSourcePath);
            var testAssembly = Assembly.Load(File.ReadAllBytes(stream.OriginalSourcePath));

            var package = new TestPackage(testAssembly.GetName().FullName);
            TestExecutionContext.CurrentContext.TestPackage = package;

            var builder = new NamespaceTreeBuilder(new TestAssembly(testAssembly, testAssembly.GetName().FullName));
            var fixtures =
                testAssembly.GetTypes()
                    .Where(TestFixtureBuilder.CanBuildFrom)
                    .Select(TestFixtureBuilder.BuildFrom)
                    .ToList();

            builder.Add(fixtures);
            builder.RootSuite.Run(new ConsoleListener(), TestFilter.Empty);
        }
コード例 #4
0
ファイル: TestBuilder.cs プロジェクト: jimgraham/visual-nunit
        private TestSuite BuildTestAssembly(string assemblyName, IList fixtures, bool autoSuites)
        {
            TestSuite testAssembly = new TestSuite(assemblyName);

            if (autoSuites)
            {
                NamespaceTreeBuilder treeBuilder =
                    new NamespaceTreeBuilder(testAssembly);
                treeBuilder.Add(fixtures);
                testAssembly = treeBuilder.RootSuite;
            }
            else
                foreach (TestSuite fixture in fixtures)
                {
                    if (fixture is SetUpFixture)
                    {
                        fixture.RunState = RunState.NotRunnable;
                        fixture.IgnoreReason = "SetUpFixture cannot be used when loading tests as a flat list of fixtures";
                    }

                    testAssembly.Add(fixture);
                }

            if (fixtures.Count == 0)
            {
                testAssembly.RunState = RunState.NotRunnable;
                testAssembly.IgnoreReason = "Has no TestFixtures";
            }

            NUnitFramework.ApplyCommonAttributes(assembly, testAssembly);

            testAssembly.Properties["_PID"] = System.Diagnostics.Process.GetCurrentProcess().Id;
            testAssembly.Properties["_APPDOMAIN"] = AppDomain.CurrentDomain.FriendlyName;

            // TODO: Make this an option? Add Option to sort assemblies as well?
            testAssembly.Sort();

            return testAssembly;
        }
コード例 #5
0
ファイル: TestSuiteBuilder.cs プロジェクト: nobled/mono
		/// <summary>
		/// Build a suite based on a TestPackage
		/// </summary>
		/// <param name="package">The TestPackage</param>
		/// <returns>A TestSuite</returns>
		public TestSuite Build( TestPackage package )
		{
			bool autoNamespaceSuites = package.GetSetting( "AutoNamespaceSuites", true );
			bool mergeAssemblies = package.GetSetting( "MergeAssemblies", false );

			if ( package.IsSingleAssembly )
				return BuildSingleAssembly( package );
			string targetAssemblyName = null;
			if( package.TestName != null && package.Assemblies.Contains( package.TestName ) )
			{
				targetAssemblyName = package.TestName;
				package.TestName = null;
			}
			
			TestSuite rootSuite = new TestSuite( package.FullName );
			NamespaceTreeBuilder namespaceTree = 
				new NamespaceTreeBuilder( rootSuite );

			builders.Clear();
			foreach(string assemblyName in package.Assemblies)
			{
				if ( targetAssemblyName == null || targetAssemblyName == assemblyName )
				{
					TestAssemblyBuilder builder = new TestAssemblyBuilder();
					builders.Add( builder );

					Test testAssembly =  builder.Build( assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies );

					if ( testAssembly != null )
					{
						if (!mergeAssemblies)
						{
							rootSuite.Add(testAssembly);
						}
						else if (autoNamespaceSuites)
						{
							namespaceTree.Add(testAssembly.Tests);
							rootSuite = namespaceTree.RootSuite;
						}
						else
						{
							foreach (Test test in testAssembly.Tests)
								rootSuite.Add(test);
						}
					}
				}
			}

			if ( rootSuite.Tests.Count == 0 )
				return null;

			return rootSuite;
		}
コード例 #6
0
 /// <summary>
 /// Converts a given assembly containing tests to a runnable TestSuite
 /// </summary>
 protected static TestSuite GetTestSuiteFromAssembly(Assembly assembly)
 {
     var treeBuilder = new NamespaceTreeBuilder(
         new TestAssembly(assembly, assembly.GetName().FullName));
     treeBuilder.Add(GetFixtures(assembly));
     return treeBuilder.RootSuite;
 }
コード例 #7
0
        /// <summary>
        /// Build a suite based on a TestPackage
        /// </summary>
        /// <param name="package">The TestPackage</param>
        /// <returns>A TestSuite</returns>
        public TestSuite Build(TestPackage package)
        {
            bool autoNamespaceSuites = package.GetSetting("AutoNamespaceSuites", true);
            bool mergeAssemblies     = package.GetSetting("MergeAssemblies", false);
            bool checkCompatibility  = package.GetSetting("NUnit3Compatibility", false);

            TestExecutionContext.CurrentContext.TestCaseTimeout = package.GetSetting("DefaultTimeout", 0);

            if (package.IsSingleAssembly)
            {
                return(BuildSingleAssembly(package));
            }
            string targetAssemblyName = null;

            if (package.TestName != null && package.Assemblies.Contains(package.TestName))
            {
                targetAssemblyName = package.TestName;
                package.TestName   = null;
            }

            TestSuite            rootSuite     = new ProjectRootSuite(package.FullName);
            NamespaceTreeBuilder namespaceTree =
                new NamespaceTreeBuilder(rootSuite);

            builders.Clear();
            foreach (string assemblyName in package.Assemblies)
            {
                if (targetAssemblyName == null || targetAssemblyName == assemblyName)
                {
                    TestAssemblyBuilder builder = new TestAssemblyBuilder();
                    builders.Add(builder);

                    Test testAssembly = builder.Build(assemblyName, package.TestName, autoNamespaceSuites && !mergeAssemblies, checkCompatibility);

                    if (testAssembly != null)
                    {
                        if (!mergeAssemblies)
                        {
                            rootSuite.Add(testAssembly);
                        }
                        else if (autoNamespaceSuites)
                        {
                            namespaceTree.Add(testAssembly.Tests);
                            rootSuite = namespaceTree.RootSuite;
                        }
                        else
                        {
                            foreach (Test test in testAssembly.Tests)
                            {
                                rootSuite.Add(test);
                            }
                        }
                    }
                }
            }

            ProviderCache.Clear();

            if (rootSuite.Tests.Count == 0)
            {
                return(null);
            }

            return(rootSuite);
        }