public Test BuildFrom(Type type)
 {
     var testSuite = new TestSuite(type.FullName);
     testSuite.Add(new ConcordionTest(type));
     NUnitFramework.ApplyCommonAttributes(type, testSuite);
     return testSuite;
 }
Beispiel #2
0
		protected void Page_Load(object sender, EventArgs e)
		{
			// Initialise data table to hold test results
			m_results.Columns.Add("test");
			m_results.Columns.Add("result");
            m_results.Columns.Add("time");
			m_results.Columns.Add("message");
			m_results.Columns.Add("class");

			// Initialise controls
			lblResult.Text = "";
			ltlStats.Text = "";

			// Initialise NUnit
			CoreExtensions.Host.InitializeService();

			// Find tests in current assembly
			TestPackage package = new TestPackage(Assembly.GetExecutingAssembly().Location);
			m_testSuite = new TestSuiteBuilder().Build(package);

			if (!IsPostBack)
			{
				// Display category filters
				StringCollection coll = new StringCollection();
				GetCategories((TestSuite)m_testSuite, coll);
				string[] cats = new string[coll.Count];
				coll.CopyTo(cats, 0);
				Array.Sort(cats);
				cblCategories.DataSource = cats;
				cblCategories.DataBind();
			}
		}
 public NUnitBasicTestEngine(string productName)
 {
     List<String> assemblies = GetAssembliesWithTests ().Select (a=>a.Location).ToList ();
     TestSuite suite = PrepareTestSuite (assemblies);
     testSuite = suite;
     this.productName = productName;
 }
 private void ExecuteTestSuite( TestSuite suite, UnitTestRunner.ITestRunnerCallback testRunnerEventListener, TestFilter filter )
 {
     EventListener eventListener;
     if (testRunnerEventListener == null)
         eventListener = new NullListener ();
     else
         eventListener = new TestRunnerEventListener (testRunnerEventListener);
     suite.Run(eventListener, GetFilter(filter));
 }
Beispiel #5
0
        public void HighLevelSuite()
        {
            NUnit.Core.TestSuite mockTest = (NUnit.Core.TestSuite)findTest("MockTestFixture", testSuite);
            NameFilter           filter   = new NameFilter(testSuite);

            Assert.IsTrue(filter.Pass(mock3), "Name Filter did not pass test case");
            Assert.IsTrue(filter.Pass(mockTest), "Name Filter did not pass middle suite");
            Assert.IsTrue(filter.Pass(testSuite), "Name Filter did not pass test suite");
        }
Beispiel #6
0
        public void SuiteNameMatch()
        {
            NUnit.Core.TestSuite mockTest = (NUnit.Core.TestSuite)findTest("MockTestFixture", testSuite);
            NameFilter           filter   = new NameFilter(mockTest);

            Assert.IsTrue(filter.Pass(mock3), "Name Filter did not pass test case");
            Assert.IsTrue(filter.Pass(mockTest), "Suite did not pass test case");
            Assert.IsTrue(filter.Pass(testSuite), "Suite did not pass test case");
        }
        public TestT BuildFrom(MethodInfo method, TestT parentSuite)
        {
            TestSuite testT = new TestSuite(method.Name);
            NUnitFramework.ApplyCommonAttributes(method, testT);

            ArrayList hierachyNodeList = new ArrayList();
            foreach (ProviderReference reference in GetBuildersFor(method, parentSuite))
            {
                System.Collections.Specialized.ListDictionary contextProperties
                     = new System.Collections.Specialized.ListDictionary();
                //테스트 함수에 지정된 특성값을 계층노드의 속성으로 복사합니다.
                foreach (DictionaryEntry entry in testT.Properties)
                {
                    if ((string)entry.Key != DESCRIPTION
                        && (string)entry.Key != CATEGORIES)
                    {
                        contextProperties[entry.Key] = entry.Value;
                    }
                }

                HierachyNode baseNode = new HierachyNode(method.Name);
                baseNode = reference.GetInstance(baseNode, contextProperties) as HierachyNode;
                if (baseNode != null)
                {
                    hierachyNodeList.Add(baseNode);
                }
            }

            ArrayList testSuiteList = new ArrayList();
            foreach (HierachyNode hierachyNode in hierachyNodeList)
            {
                TestSuite testSuite = new TestSuite(hierachyNode.Name);
                this.BuildTestSuiteTree(method, ref testSuite, hierachyNode);
                testSuiteList.Add(testSuite);
            }

            if (testSuiteList.Count > 0)
            {
                if (testSuiteList.Count == 1)
                {
                    testT = testSuiteList[0] as TestSuite;
                }
                else
                {
                    testT = new TestSuite(method.Name);
                    NUnitFramework.ApplyCommonAttributes(method, testT);
                    foreach (TestSuite testSuite in testSuiteList)
                    {
                        testT.Add(testSuite);
                    }
                }
            }

            return testT;
        }
		/// <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 );
            TestContext.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 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;
		}
 private static void CreateTests(TestSuite fixture, XmlElement fixtureElement)
 {
     foreach (XmlElement testElement in fixtureElement.SelectNodes("Test"))
     {
         string name = testElement.GetAttribute("Name");
         if (name.Length > 0)
         {
             GrammarTest test = new GrammarTest(fixture.Name, name, testElement);
             fixture.Add(test);
         }
     }
 }
 public TestSuite BuildFrom(Type type, int assemblyKey)
 {
     TestSuite suite = new TestSuite("FlexWiki Grammar Tests");
     Assembly assembly = Assembly.GetExecutingAssembly();
     using (Stream stream = assembly.GetManifestResourceStream(this.GetType(), "FlexWikiGrammarTests.xml"))
     {
         XmlDocument suiteDoc = new XmlDocument();
         suiteDoc.Load(stream);
         CreateTestFixtures(suite, suiteDoc);
     }
     return suite;
 }
 private static void CreateTestFixtures(TestSuite suite, XmlDocument suiteDoc)
 {
     foreach (XmlElement fixtureElement in suiteDoc.DocumentElement.SelectNodes("TestFixture"))
     {
         string name = fixtureElement.GetAttribute("Name");
         if (name.Length > 0)
         {
             TestSuite fixture = new TestSuite(name);
             suite.Add(fixture);
             CreateTests(fixture, fixtureElement);
         }
     }
 }
Beispiel #12
0
		public override bool Pass(TestSuite suite) 
		{
			bool passed = Exclude;

			foreach (Test node in testNodes) 
			{
				if (suite.IsDescendant(node) || node.IsDescendant(suite) || node == suite) 
				{
					passed = !Exclude;
					break;
				}
			}

			return passed;
		}
		public void Add( TestSuite fixture )
		{
            if (fixture != null)
            {
                string ns = fixture.TestName.FullName;
                int index = ns.IndexOf("[");
                if (index >= 0) ns = ns.Substring(0, index);
                index = ns.LastIndexOf('.');
                ns = index > 0 ? ns.Substring(0, index) : string.Empty;
                TestSuite containingSuite = BuildFromNameSpace(ns);

                if (fixture is SetUpFixture)
                {
                    // The SetUpFixture must replace the namespace suite
                    // in which it is "contained". 
                    //
                    // First, add the old suite's children
                    foreach (TestSuite child in containingSuite.Tests)
                        fixture.Add(child);

                    // Make the parent of the containing suite point to this
                    // fixture instead
                    // TODO: Get rid of this somehow?
                    TestSuite parent = (TestSuite)containingSuite.Parent;
                    if (parent == null)
                    {
                        fixture.TestName.Name = rootSuite.TestName.Name;
                        rootSuite = fixture;
                    }
                    else
                    {
                        parent.Tests.Remove(containingSuite);
                        parent.Add(fixture);
                    }

                    // Update the hashtable
                    namespaceSuites[ns] = fixture;
                }
                else
                    containingSuite.Add(fixture);
            }
		}
Beispiel #14
0
        public UnitTestRendererLine GetTests(out UnitTestResult[] results, out string[] categories)
        {
            if (m_TestSuite == null)
            {
                var assemblies = GetAssembliesWithTests().Select(a => a.Location).ToList();
                TestSuite suite = PrepareTestSuite(assemblies);
                m_TestSuite = suite;
            }

            var resultList = new List<UnitTestResult>();
            var categoryList = new HashSet<string>();

            UnitTestRendererLine lines = null;
            if (m_TestSuite != null)
                lines = ParseTestList(m_TestSuite, resultList, categoryList).Single();
            results = resultList.ToArray();
            categories = categoryList.ToArray();

            return lines;
        }
Beispiel #15
0
        private static DirectTestSuite directize(TestSuite suite, string filter)
        {
            var result = new DirectTestSuite(suite);

            // replace all TestSuite's with DirectTestSuite's recursively... ugh...
            Queue<Test> tests = new Queue<Test>();
            tests.Enqueue(result);
            while (tests.Count > 0)
            {
                var test = tests.Dequeue();
                if (test.Tests == null)
                    continue;
                var subtests = test.Tests.Cast<Test>().ToList();
                test.Tests.Clear();
                foreach (var subtest in subtests)
                {
                    if (subtest is TestSuite)
                    {
                        var replacement = new DirectTestSuite((TestSuite) subtest);
                        test.Tests.Add(replacement);
                        tests.Enqueue(replacement);
                    }
                    else if (subtest is TestMethod)
                    {
                        if (filter == null || Regex.IsMatch(subtest.TestName.FullName, filter))
                        {
                            var replacement = new DirectTestMethod((TestMethod) subtest);
                            test.Tests.Add(replacement);
                            tests.Enqueue(replacement);
                        }
                    }
                    else
                    {
                        test.Tests.Add(subtest);
                        tests.Enqueue(subtest);
                    }
                }
            }

            return result;
        }
Beispiel #16
0
        public Test BuildFrom(Type type)
        {
            var instance = Reflect.Construct(type);
            var result = new TestSuite(type) {Fixture = instance};

            foreach (var property in GetTestSourcePropertiesFrom(type))
            {
                var testSource = (ITestSource) property.GetValue(instance, null);
                if (!testSource.TestContext.HasTests)
                    continue;

                var suite = new TestSuite(string.Format("{0} {1}", testSource.TestContext.ArrangeDescription,
                                                        testSource.TestContext.ActDescription));
                foreach (var testInformation in testSource.TestContext.Tests)
                {
                    suite.Add(new LingualTest(testInformation));
                }
                result.Add(suite);
            }
            return result;
        }
        public Test BuildFrom(MethodInfo method)
        {
            Attribute attrib = Reflect.GetAttribute(method, IterativeTestAttribute, false);
            string[] functionNames = IterativeTestFramework.GetDataSetNames(attrib);
            TestSuite suite = new TestSuite(method.Name);

            object tester = Reflect.Construct(method.DeclaringType);
            List<object> dataset = new List<object>();
            foreach (string name in functionNames)
            {
                MethodInfo m = tester.GetType().GetMethod(name);
                if (m == null)
                    dataset.Add(tester.GetType().GetProperty(name).GetValue(tester, null));
                else
                    dataset.Add(m.Invoke(tester, null));

            }

            AddDataSet(ref suite, method, new List<object>(), 0, dataset);

            return suite;
        }
Beispiel #18
0
		public override bool Pass(TestSuite suite)
		{
//			return CheckCategories( suite ) ? !Exclude : Exclude;

			if ( categories.Count == 0 ) return true;

			bool pass = Exclude;

			if (CheckCategories(suite))
				return !Exclude;

			foreach (Test test in suite.Tests) 
			{
				if ( test.Filter(this) == !Exclude )
				{
					pass=true;
					break;
				}
			}

			return pass;
		}
Beispiel #19
0
        /// <summary>
        /// Go through the Test tree, building a tree of TestFixures with Test nodes. 
        /// </summary>
        private void MapTestTreeToFixtures(TreeDictionary<string, TestClosure> source, TestSuite container, Type fixtureType)
        {
            foreach (var testClosure in source.Items) {
                container.Add(new ClosureTest(testClosure));
            }

            foreach (var child in source.Children) {
                var fixture = new TestFixture(fixtureType);
                fixture.TestName.Name = child.Key;
                foreach (var testClosure in child.Value.Items) {
                    fixture.Add(new ClosureTest(testClosure));
                }

                foreach (var sub_child in child.Value.Children) {
                    var sub_fixture = new TestFixture(fixtureType);
                    sub_fixture.TestName.Name = sub_child.Key;
                    MapTestTreeToFixtures(sub_child.Value, sub_fixture, fixtureType);
                    fixture.Add(sub_fixture);
                }
                container.Add(fixture);
            }
        }
 private void AddDataSet(ref TestSuite suite, MethodInfo method, List<object> arguments, int counter, List<object> dataset)
 {
     if (counter >= dataset.Count)
         suite.Add(new IterativeTestCase(method, arguments.ToArray()));
     else
     {
         if (dataset[counter].GetType().GetInterface("IEnumerable") != null)
         {
             foreach (object arg in (IEnumerable)dataset[counter])
             {
                 List<object> new_args = new List<object>(arguments);
                 new_args.Add(arg);
                 AddDataSet(ref suite, method, new_args, counter + 1, dataset);
             }
         }
         else
         {
             List<object> new_args = new List<object>(arguments);
             new_args.Add(dataset[counter]);
             AddDataSet(ref suite, method, new_args, counter + 1, dataset);
         }
     }
 }
Beispiel #21
0
		public abstract bool Pass(TestSuite suite);
Beispiel #22
0
 public DirectTestSuite(TestSuite suite)
     : base(suite.TestName.Name)
 {
     foreach (var fld in typeof(TestSuite).GetAllFields())
         fld.SetValue(this, fld.GetValue(suite));
     if (Tests != null)
         foreach (Test child in Tests)
             child.Parent = this;
 }
Beispiel #23
0
        /// <summary>
        /// Find all available categories in the test suite
        /// </summary>
        /// <param name="suite">The test suite to get categories from</param>
        /// <param name="cats">Output collection containing categories found</param>
        private void GetCategories(TestSuite suite, StringCollection cats)
        {
            if (suite.Categories != null)
            {
                for (int i = 0; i < suite.Categories.Count; i++)
                    if (!cats.Contains((string)suite.Categories[i]))
                        cats.Add((string)suite.Categories[i]);
            }

            for (int i = 0; i < suite.Tests.Count; i++)
                if(((ITest)suite.Tests[i]).IsSuite)
                    GetCategories((TestSuite)suite.Tests[i], cats);
        }
Beispiel #24
0
		private TestSuite BuildFromNameSpace( string nameSpace, int assemblyKey )
		{
			if( nameSpace == null || nameSpace  == "" ) return rootSuite;
			TestSuite suite = (TestSuite)namespaceSuites[nameSpace];
			if(suite!=null) return suite;

			int index = nameSpace.LastIndexOf(".");
			string prefix = string.Format( "[{0}]", assemblyKey );
			if( index == -1 )
			{
				suite = new NamespaceSuite( nameSpace, assemblyKey );
				if ( rootSuite == null )
					rootSuite = suite;
				else
					rootSuite.Add(suite);
				namespaceSuites[nameSpace]=suite;
			}
			else
			{
				string parentNameSpace = nameSpace.Substring( 0,index );
				TestSuite parent = BuildFromNameSpace( parentNameSpace, assemblyKey );
				string suiteName = nameSpace.Substring( index+1 );
				suite = new NamespaceSuite( parentNameSpace, suiteName, assemblyKey );
				parent.Add( suite );
				namespaceSuites[nameSpace] = suite;
			}

			return suite;
		}
		private NUnit.Core.TestResult ExecuteTestSuite(TestSuite suite, UnitTestRunner.ITestRunnerCallback testRunnerEventListener, ITestFilter filter)
		{
			var result = suite.Run(new TestRunnerEventListener(testRunnerEventListener),
									filter);
			return result;
		}
 public NamespaceTreeBuilder(TestSuite rootSuite)
 {
     this.rootSuite = rootSuite;
 }
 public MockTestEventSource( TestSuite suite )
 {
     this.suite = suite;
     //this.testFileName = testFileName;
 }
Beispiel #28
0
		public NamespaceTreeBuilder( TestSuite rootSuite )
		{
			this.rootSuite = rootSuite;
		}
Beispiel #29
0
        /// <summary>
        /// Find an NUnit test fixture by name.
        /// </summary>
        /// <param name="fixture"></param>
        /// <param name="suite"></param>
        /// <param name="name"></param>
        private static void FindFixtureByName(out TestFixture fixture, TestSuite suite, string name)
        {
            foreach (TestSuite innerSuite in suite.Tests)
            {
                if (innerSuite is TestFixture)
                {
                    if (((TestFixture)innerSuite).TestName.Name == name)
                    {
                        fixture = innerSuite as TestFixture;
                        return;
                    }
                }
                else
                {
                    FindFixtureByName(out fixture, innerSuite, name);
                    if (fixture != null)
                        return;
                }
            }

            fixture = null;
        }
Beispiel #30
0
		public GroupLine (TestSuite suite)
			: base (suite)
		{
			if (suite is NamespaceSuite) renderedName = fullName;
		}
Beispiel #31
0
        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;
        }
Beispiel #32
0
 private void UpdateTestResults(NUnit.Core.TestSuite suite)
 {
     ToUnitTestResult(suite);
 }
Beispiel #33
0
		public void SuiteStarted(TestSuite suite){}
Beispiel #34
0
			public void SuiteStarted(TestSuite suite) 
			{
				if ( debugger && level++ == 0 )
				{
					testRunCount = 0;
					testIgnoreCount = 0;
					failureCount = 0;
					Trace.WriteLine( "################################ UNIT TESTS ################################" );
					Trace.WriteLine( "Running tests in '" + suite.FullName + "'..." );
				}
			}
Beispiel #35
0
 public abstract bool Pass(TestSuite suite);