private Test BuildMultipleFixtures(Type type, Attribute[] attrs)
        {
            TestSuite suite = new TestSuite(type.Namespace, TypeHelper.GetDisplayName(type));

            foreach (Attribute attr in attrs)
                suite.Add(BuildSingleFixture(type, attr));

            return suite;
        }
 public override ITestSuite GetTests()
 {
     TestSuite suite = new TestSuite(this.Name);
     int index = 0;
     foreach(Delegate del in Test.GetInvocationList())
     {
         string name = String.Format("Test{0}", index).TrimEnd('0');
         ITestCase tc = CreateTestCase(del, name);
         suite.Add(tc);
         index++;
     }
     return suite;
 }
Ejemplo n.º 3
0
        private TestSuite BuildFromNameSpace(string ns)
        {
            if (ns == null || ns == "")
            {
                return(rootSuite);
            }

            TestSuite suite = namespaceSuites.ContainsKey(ns)
                ? namespaceSuites[ns]
                : null;

            if (suite != null)
            {
                return(suite);
            }

            int index = ns.LastIndexOf(".");

            if (index == -1)
            {
                suite = new TestSuite(ns);
                if (rootSuite == null)
                {
                    rootSuite = suite;
                }
                else
                {
                    rootSuite.Add(suite);
                }
            }
            else
            {
                string    parentNamespace = ns.Substring(0, index);
                TestSuite parent          = BuildFromNameSpace(parentNamespace);
                string    suiteName       = ns.Substring(index + 1);
                suite = new TestSuite(parentNamespace, suiteName);
                parent.Add(suite);
            }

            namespaceSuites[ns] = suite;
            return(suite);
        }
Ejemplo n.º 4
0
        public override ITestSuite GetTests()
        {
            TestSuite suite = new TestSuite(this.Name);

            if (this.Test == null)
            {
                return(suite);
            }

            int index = 0;

            foreach (Delegate del in Test.GetInvocationList())
            {
                string    name = String.Format("Test{0}", index).TrimEnd('0');
                ITestCase tc   = CreateTestCase(del, name);
                suite.Add(tc);
                index++;
            }
            return(suite);
        }
Ejemplo n.º 5
0
        private RowTestCase CreateRowTestCase(TestClass fixture, string methodName, params object[] arguments)
        {
            MethodInfo method = GetTestClassMethod(methodName);

            NUnitTestFixture nunitTestFixture = new NUnitTestFixture(fixture.GetType());

            nunitTestFixture.Fixture = fixture;

            TestSuite suite = new TestSuite(nunitTestFixture.TestName.Name, method.Name);

            suite.Parent  = nunitTestFixture;
            suite.Fixture = fixture;

            RowTestCase testCase = new RowTestCase(method, method.Name, arguments);

            testCase.Fixture = fixture;
            suite.Add(testCase);

            return(testCase);
        }
Ejemplo n.º 6
0
        public void RunTestExcludingCategory()
        {
            TestSuite testSuite = new TestSuite("Mock Test Suite");

            testSuite.Add(mockTestFixture);

            CategoryFilter filter = new CategoryFilter();

            filter.AddCategory("MockCategory");
            RecordingListener listener  = new RecordingListener();
            NotFilter         notFilter = new NotFilter(filter);

            notFilter.TopLevel = true;
            testSuite.Run(listener, notFilter);
            CollectionAssert.AreEquivalent(
                new string[] { "MockTest1", "MockTest4", "MockTest5",
                               "TestWithManyProperties", "NotRunnableTest", "FailingTest",
                               "TestWithException", "InconclusiveTest" },
                listener.testStarted);
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            MethodInfo fakeTestMethod = GetType().GetMethod("FakeTestCase", BindingFlags.Instance | BindingFlags.NonPublic);
            var        nunitTest      = new NUnitTestMethod(fakeTestMethod);

            nunitTest.Categories.Add("cat1");
            nunitTest.Properties.Add("Priority", "medium");

            var nunitFixture = new TestSuite("FakeNUnitFixture");

            nunitFixture.Categories.Add("super");
            nunitFixture.Add(nunitTest);

            Assert.That(nunitTest.Parent, Is.SameAs(nunitFixture));

            var fixtureNode = new TestNode(nunitFixture);

            fakeNUnitTest = (ITest)fixtureNode.Tests[0];

            testConverter = new TestConverter(new TestLogger(), ThisAssemblyPath);
        }
Ejemplo n.º 8
0
        public void IgnoredFixtureShouldNotCallFixtureSetUpOrTearDown()
        {
            IgnoredFixture fixture      = new IgnoredFixture();
            TestSuite      suite        = new TestSuite("IgnoredFixtureSuite");
            TestSuite      fixtureSuite = TestBuilder.MakeFixture(fixture.GetType());
            TestMethod     testMethod   = (TestMethod)fixtureSuite.Tests[0];

            suite.Add(fixtureSuite);

            TestBuilder.RunTest(fixtureSuite, fixture);
            Assert.IsFalse(fixture.setupCalled, "TestFixtureSetUp called running fixture");
            Assert.IsFalse(fixture.teardownCalled, "TestFixtureTearDown called running fixture");

            TestBuilder.RunTest(suite, fixture);
            Assert.IsFalse(fixture.setupCalled, "TestFixtureSetUp called running enclosing suite");
            Assert.IsFalse(fixture.teardownCalled, "TestFixtureTearDown called running enclosing suite");

            TestBuilder.RunTest(testMethod, fixture);
            Assert.IsFalse(fixture.setupCalled, "TestFixtureSetUp called running a test case");
            Assert.IsFalse(fixture.teardownCalled, "TestFixtureTearDown called running a test case");
        }
Ejemplo n.º 9
0
        public void IgnoredFixtureShouldNotCallFixtureSetUpOrTearDown()
        {
            IgnoredFixture fixture      = new IgnoredFixture();
            TestSuite      suite        = new TestSuite("IgnoredFixtureSuite");
            TestSuite      fixtureSuite = TestBuilder.MakeFixture(fixture.GetType());

            suite.Fixture = fixture;
            NUnit.Core.TestCase testCase = (NUnit.Core.TestCase)fixtureSuite.Tests[0];
            suite.Add(fixtureSuite);

            fixtureSuite.Run(NullListener.NULL);
            Assert.IsFalse(fixture.setupCalled, "TestFixtureSetUp called running fixture");
            Assert.IsFalse(fixture.teardownCalled, "TestFixtureTearDown called running fixture");

            suite.Run(NullListener.NULL);
            Assert.IsFalse(fixture.setupCalled, "TestFixtureSetUp called running enclosing suite");
            Assert.IsFalse(fixture.teardownCalled, "TestFixtureTearDown called running enclosing suite");

            testCase.Run(NullListener.NULL);
            Assert.IsFalse(fixture.setupCalled, "TestFixtureSetUp called running a test case");
            Assert.IsFalse(fixture.teardownCalled, "TestFixtureTearDown called running a test case");
        }
Ejemplo n.º 10
0
        internal static void Run(string title, Stream outputStream)
        {
            var suite   = new TestSuite(title);
            var builder = new NUnitLiteTestAssemblyBuilder();

            suite.Add(builder.Build(System.Reflection.Assembly.GetExecutingAssembly(), new Dictionary <string, object>()));

            var testExecutionContext = TestExecutionContext.CurrentContext;

            testExecutionContext.WorkDirectory = Environment.CurrentDirectory;

            var workItem = suite.CreateWorkItem(TestFilter.Empty);

            workItem.Execute(testExecutionContext);

            var testWriter = new NUnitLite.Runner.NUnit2XmlOutputWriter(DateTime.Now);

            using (var writer = new StreamWriter(outputStream))
            {
                testWriter.WriteResultFile(workItem.Result, writer);
            }
        }
Ejemplo n.º 11
0
        public IEnumerator <ITest> BuildAsync(Assembly[] assemblies, TestPlatform[] testPlatforms, IDictionary <string, object> options)
        {
            var productName = string.Join("_", m_ProductName.Split(Path.GetInvalidFileNameChars()));
            var suite       = new TestSuite(productName);

            for (var index = 0; index < assemblies.Length; index++)
            {
                var assembly = assemblies[index];
                var platform = testPlatforms[index];

                var assemblySuite = Build(assembly, options) as TestSuite;
                if (assemblySuite != null && assemblySuite.HasChildren)
                {
                    assemblySuite.Properties.Set("platform", platform);
                    suite.Add(assemblySuite);
                }

                yield return(null);
            }

            yield return(suite);
        }
Ejemplo n.º 12
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);

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

            return(testAssembly);
        }
Ejemplo n.º 13
0
        private void AddDynamicTestFixtures(TestSuite mainSuite, IAutoTestFixture autoTestFixture, AutoTestMode autoTestMode)
        {
            var suite = new TestSuite(autoTestMode.ToString());

            mainSuite.Add(suite);
            foreach (var testSettings in autoTestFixture.GetAutoTestSettings())
            {
                if ((testSettings.Mode & autoTestMode) != autoTestMode)
                {
                    continue;
                }
                testSettings.Mode = autoTestMode;
//				testSettings.StoreKnownGood = testSettings.StoreKnownGood && testSettings.Mode == AutoTestMode.Historical;
                var fixture = new NUnitTestFixture(userFixtureType, new object[] { testSettings });
                fixture.TestName.Name = testSettings.Name;
                suite.Add(fixture);
                AddStrategyTestCases(fixture, testSettings);
                if (testSettings.Mode == AutoTestMode.SimulateRealTime)
                {
                    AddSymbolTestCases(fixture, testSettings);
                }
            }
        }
Ejemplo n.º 14
0
        private void AddDynamicTestFixtures(TestSuite mainSuite, IAutoTestFixture autoTestFixture, AutoTestMode autoTestMode)
        {
            var suite = new TestSuite(autoTestMode.ToString());

            mainSuite.Add(suite);
            foreach (var testSettings in autoTestFixture.GetAutoTestSettings())
            {
                if ((testSettings.Mode & autoTestMode) != autoTestMode)
                {
                    continue;
                }
                testSettings.Mode = autoTestMode;
                var fixture = new NUnitTestFixture(userFixtureType, new object[] { testSettings.Name, testSettings });
                foreach (var category in testSettings.Categories)
                {
                    fixture.Categories.Add(category);
                }
                fixture.Categories.Add(Enum.GetName(typeof(AutoTestMode), autoTestMode));
                fixture.TestName.Name = testSettings.Name;
                suite.Add(fixture);
                AddStrategyTestCases(fixture, testSettings);
            }
        }
Ejemplo n.º 15
0
        public void CountTestCasesFilteredByName()
        {
            TestSuite testSuite = new TestSuite("Mock Test Suite");

            testSuite.Add(mockTestFixture);
            Assert.AreEqual(MockTestFixture.Tests, testSuite.TestCount);

            NUnit.Core.TestCase mock3  = (NUnit.Core.TestCase)TestFinder.Find("MockTest3", testSuite);
            NUnit.Core.TestCase mock1  = (NUnit.Core.TestCase)TestFinder.Find("MockTest1", testSuite);
            NameFilter          filter = new NameFilter(mock3.TestName);

            Assert.AreEqual(1, testSuite.CountTestCases(filter));

            filter = new NameFilter();
            filter.Add(mock3.TestName);
            filter.Add(mock1.TestName);

            Assert.AreEqual(2, testSuite.CountTestCases(filter));

            filter = new NameFilter(testSuite.TestName);

            Assert.AreEqual(MockTestFixture.Tests - MockTestFixture.Explicit, testSuite.CountTestCases(filter));
        }
Ejemplo n.º 16
0
        public void CountTestCasesFilteredByName()
        {
            TestSuite testSuite = new TestSuite("Mock Test Suite");

            testSuite.Add(mockTestFixture);
            Assert.AreEqual(MockTestFixture.Tests, testSuite.TestCount);

            Test       mock3  = TestFinder.Find("MockTest3", testSuite, true);
            Test       mock1  = TestFinder.Find("MockTest1", testSuite, true);
            NameFilter filter = new NameFilter(mock3.TestName);

            Assert.AreEqual(1, testSuite.CountTestCases(filter));

            filter = new NameFilter();
            filter.Add(mock3.TestName);
            filter.Add(mock1.TestName);

            Assert.AreEqual(2, testSuite.CountTestCases(filter));

            filter = new NameFilter(testSuite.TestName);

            Assert.AreEqual(MockTestFixture.ResultCount, testSuite.CountTestCases(filter));
        }
Ejemplo n.º 17
0
        public void RerunFixtureAfterTearDownFixed()
        {
            MisbehavingFixtureTearDown testFixture = new MisbehavingFixtureTearDown();
            TestSuite suite = new TestSuite("ASuite");

            suite.Add(testFixture);
            TestSuiteResult result = (TestSuiteResult)suite.Run(NullListener.NULL);

            Assert.AreEqual(1, result.Results.Count);

            // should have one suite and one fixture
            ResultSummarizer summ = new ResultSummarizer(result);

            Assert.AreEqual(1, summ.ResultCount);
            Assert.AreEqual(0, summ.TestsNotRun);
            Assert.AreEqual(0, summ.SuitesNotRun);

            testFixture.blowUp = false;
            result             = (TestSuiteResult)suite.Run(NullListener.NULL);
            summ = new ResultSummarizer(result);
            Assert.AreEqual(1, summ.ResultCount);
            Assert.AreEqual(0, summ.TestsNotRun);
            Assert.AreEqual(0, summ.SuitesNotRun);
        }
Ejemplo n.º 18
0
        public void HandleErrorInFixtureTearDown()
        {
            MisbehavingFixtureTearDown testFixture = new MisbehavingFixtureTearDown();
            TestSuite suite = new TestSuite("ASuite");

            suite.Add(testFixture);
            TestSuiteResult result = (TestSuiteResult)suite.Run(NullListener.NULL);

            Assert.AreEqual(1, result.Results.Count);
            TestResult failedResult = ((TestResult)result.Results[0]);

            Assert.IsTrue(failedResult.Executed, "Suite should have executed");
            Assert.IsTrue(failedResult.IsFailure, "Suite should have failed");

            Assert.AreEqual("This was thrown from fixture teardown", failedResult.Message);
            Assert.IsNotNull(failedResult.StackTrace, "StackTrace should not be null");

            // should have one suite and one fixture
            ResultSummarizer summ = new ResultSummarizer(result);

            Assert.AreEqual(1, summ.ResultCount);
            Assert.AreEqual(0, summ.TestsNotRun);
            Assert.AreEqual(0, summ.SuitesNotRun);
        }
        /// <summary>
        /// Adds the specified fixture to the tree.
        /// </summary>
        /// <param name="fixture">The fixture to be added.</param>
        public void Add( TestSuite fixture )
        {
            string ns = fixture.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.Name = rootSuite.Name;
                    rootSuite = fixture;
                }
                else
                {
                    parent.Tests.Remove(containingSuite);
                    parent.Add(fixture);
                }

                // Update the dictionary
                namespaceSuites[ns] = fixture;
            }
            else
                containingSuite.Add( fixture );
        }
Ejemplo n.º 20
0
        public override void Run(IList <TestAssemblyInfo> testAssemblies)
        {
            if (testAssemblies == null)
            {
                throw new ArgumentNullException(nameof(testAssemblies));
            }

            if (AssemblyFilters == null || AssemblyFilters.Count == 0)
            {
                runAssemblyByDefault = true;
            }
            else
            {
                runAssemblyByDefault = AssemblyFilters.Values.Any(v => !v);
            }

            var builder   = new NUnitLiteTestAssemblyBuilder();
            var runner    = new NUnitLiteTestAssemblyRunner(builder, new FinallyDelegate());
            var testSuite = new TestSuite(NSBundle.MainBundle.BundleIdentifier);

            results = new TestSuiteResult(testSuite);

            TotalTests = 0;
            foreach (TestAssemblyInfo assemblyInfo in testAssemblies)
            {
                if (assemblyInfo == null || assemblyInfo.Assembly == null || !ShouldRunAssembly(assemblyInfo))
                {
                    continue;
                }

                if (!runner.Load(assemblyInfo.Assembly, builderSettings))
                {
                    OnWarning($"Failed to load tests from assembly '{assemblyInfo.Assembly}");
                    continue;
                }
                if (runner.LoadedTest is NUnitTest tests)
                {
                    TotalTests += tests.TestCaseCount;
                    testSuite.Add(tests);
                }

                // Messy API. .Run returns ITestResult which is, in reality, an instance of TestResult since that's
                // what WorkItem returns and we need an instance of TestResult to add it to TestSuiteResult. So, cast
                // the return to TestResult and hope for the best.
                ITestResult result = null;
                try {
                    OnAssemblyStart(assemblyInfo.Assembly);
                    result = runner.Run(this, Filter);
                } finally {
                    OnAssemblyFinish(assemblyInfo.Assembly);
                }

                if (result == null)
                {
                    continue;
                }

                var testResult = result as TestResult;
                if (testResult == null)
                {
                    throw new InvalidOperationException($"Unexpected test result type '{result.GetType ()}'");
                }
                results.AddResult(testResult);
            }

            // NUnitLite doesn't report filtered tests at all, but we can calculate here
            FilteredTests = TotalTests - ExecutedTests;
            LogFailureSummary();
        }
Ejemplo n.º 21
0
        public void AddEmptyName()
        {
            TestSuite suite = new TestSuite("Suite");

            suite.Add("", new TestDelegate(this.Test));
        }
Ejemplo n.º 22
0
        public void AddNullName()
        {
            TestSuite suite = new TestSuite("Suite");

            suite.Add(null, new TestDelegate(this.Test));
        }
Ejemplo n.º 23
0
        public void AddNullTestCase()
        {
            TestSuite suite = new TestSuite("Suite");

            suite.Add(null);
        }
 public void SetUp()
 {
     testSuite = new TestSuite("Mock Test Suite");
     testSuite.Add(TestBuilder.MakeFixture(typeof(MockTestFixture)));
     mock3 = TestFinder.Find("MockTest3", testSuite, true);
 }
Ejemplo n.º 25
0
 public RepeatedTestTest()
 {
     testSuite = new TestSuite("RepeatedTest Suite");
     testSuite.Add(new SuccessTest());
     testSuite.Add(new SuccessTest());
 }
		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 );

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

			return testAssembly;
		}
Ejemplo n.º 27
0
 public void SetUp()
 {
     testSuite = new TestSuite("Mock Test Suite");
     testSuite.Add(TestBuilder.MakeFixture(typeof(MockTestFixture)));
     mock3 = (NUnit.Core.TestCase)TestFinder.Find("MockTest3", testSuite);
 }
Ejemplo n.º 28
0
        private void AddSetUpFixture(TestSuite newSetupFixture, TestSuite containingSuite, string ns)
        {
            // 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)
                newSetupFixture.Add(child);

            if (containingSuite is SetUpFixture)
            {
                // The parent suite is also a SetupFixture. The new
                // SetupFixture is nested below the parent SetupFixture.
                // TODO: Avoid nesting of SetupFixtures somehow?
                //
                // Note: The tests have already been copied to the new
                //       SetupFixture. Thus the tests collection of
                //       the parent SetupFixture can be cleared.
                containingSuite.Tests.Clear();
                containingSuite.Add(newSetupFixture);
            }
            else
            {
                // 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)
                {
                    newSetupFixture.Name = rootSuite.Name;
                    rootSuite = newSetupFixture;
                }
                else
                {
                    parent.Tests.Remove(containingSuite);
                    parent.Add(newSetupFixture);
                }
            }

            // Update the dictionary
            namespaceSuites[ns] = newSetupFixture;
        }