Example #1
0
        public void TestWithInfiniteLoopTimesOut()
        {
            TimeoutFixture fixture    = new TimeoutFixture();
            TestSuite      suite      = TestBuilder.MakeFixture(fixture);
            TestMethod     testMethod = (TestMethod)TestFinder.Find("InfiniteLoopWith50msTimeout", suite, false);
            ITestResult    result     = TestBuilder.RunTest(testMethod, fixture);

            Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure));
            Assert.That(result.Message, Contains.Substring("50ms"));
            Assert.That(fixture.TearDownWasRun, "TearDown was not run");
        }
Example #2
0
        public void AssemblySetUpFixtureReplacesAssemblyNodeInTree()
        {
            IDictionary <string, object> options = new Dictionary <string, object>();
            var setupFixture = builder.Build(testAssembly, options) as SetUpFixture;

            Assert.IsNotNull(setupFixture);

            var testFixture = TestFinder.Find("SomeFixture", setupFixture, false);

            Assert.AreEqual(1, testFixture.Tests.Count);
        }
Example #3
0
        public void TimeoutCanBeSetOnTestFixture()
        {
            TestResult suiteResult = TestBuilder.RunTestFixture(typeof(ThreadingFixtureWithTimeout));

            Assert.That(suiteResult.ResultState, Is.EqualTo(ResultState.Failure));
            Assert.That(suiteResult.Message, Is.EqualTo("One or more child tests had errors"));
            ITestResult result = TestFinder.Find("Test2WithInfiniteLoop", suiteResult, false);

            Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure));
            Assert.That(result.Message, Contains.Substring("50ms"));
        }
        public void MultipleNameMatch()
        {
            Test             mock1  = TestFinder.Find("MockTest1", testSuite, true);
            SimpleNameFilter filter = new SimpleNameFilter();

            filter.Add("NUnit.Tests.Assemblies.MockTestFixture.MockTest3");
            filter.Add("NUnit.Tests.Assemblies.MockTestFixture.MockTest1");
            Assert.IsTrue(filter.Pass(mock3), "Name Filter did not pass test case");
            Assert.IsTrue(filter.Pass(mock1), "Name Filter did not pass test case");
            Assert.IsTrue(filter.Pass((TestSuite)testSuite.Tests[0]), "Name Filter did not pass test suite");
        }
        public void SetUpTimesOutAndTearDownIsRun()
        {
            TimeoutFixture fixture    = new TimeoutFixtureWithTimeoutInSetUp();
            TestSuite      suite      = TestBuilder.MakeFixture(fixture);
            TestMethod     testMethod = (TestMethod)TestFinder.Find("Test1", suite, false);
            ITestResult    result     = TestBuilder.RunTest(testMethod, fixture);

            Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure));
            Assert.That(result.Message, Does.Contain("50ms"));
            Assert.That(fixture.TearDownWasRun, "TearDown was not run");
        }
Example #6
0
        public void RunExplicitTestDirectly()
        {
            Test test = TestFinder.Find("ExplicitlyRunTest", mockTestFixture);

            Assert.IsNotNull(test, "Cannot find ExplicitlyRunTest");
            Assert.AreEqual(RunState.Explicit, test.RunState);
            TestResult       result     = test.Run(NullListener.NULL);
            ResultSummarizer summarizer = new ResultSummarizer(result);

            Assert.AreEqual(1, summarizer.ResultCount);
        }
            public void TestTimeOutTestCaseWithOutElapsed()
            {
                TimeoutTestCaseFixture fixture = new TimeoutTestCaseFixture();
                TestSuite suite = TestBuilder.MakeFixture(fixture);
                ParameterizedMethodSuite methodSuite = (ParameterizedMethodSuite)TestFinder.Find("TestTimeOutTestCase", suite, false);
                ITestResult result = TestBuilder.RunTest(methodSuite, fixture);

                Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure), "Suite result");
                Assert.That(result.Children.ToArray()[0].ResultState, Is.EqualTo(ResultState.Success), "First test");
                Assert.That(result.Children.ToArray()[1].ResultState, Is.EqualTo(ResultState.Failure), "Second test");
            }
Example #8
0
        public void TearDownTimesOutAndNoFurtherTearDownIsRun()
        {
            TimeoutFixture fixture    = new TimeoutFixtureWithTimeoutInTearDown();
            TestSuite      suite      = TestBuilder.MakeFixture(fixture);
            TestMethod     testMethod = (TestMethod)TestFinder.Find("Test1", suite, false);
            ITestResult    result     = TestBuilder.RunTest(testMethod, fixture);

            Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure));
            Assert.That(result.Message, Does.Contain("50ms"));
            Assert.That(fixture.TearDownWasRun, "Base TearDown should not have been run but was");
        }
Example #9
0
        public void MultipleNameMatch()
        {
            Test       mock1  = TestFinder.Find("MockTest1", testSuite, true);
            NameFilter filter = new NameFilter();

            filter.Add(mock3.TestName);
            filter.Add(mock1.TestName);
            Assert.IsTrue(filter.Pass(mock3), "Name Filter did not pass test case");
            Assert.IsTrue(filter.Pass(mock1), "Name Filter did not pass test case");
            Assert.IsTrue(filter.Pass((TestSuite)testSuite.Tests[0]), "Name Filter did not pass test suite");
        }
Example #10
0
        public void TestTimeOutTestCaseWithOutElapsed()
        {
            TimeoutTestCaseFixture fixture = new TimeoutTestCaseFixture();
            TestSuite suite = TestBuilder.MakeFixture(fixture);
            ParameterizedMethodSuite testMethod = (ParameterizedMethodSuite)TestFinder.Find("TestTimeOutTestCase", suite, false);
            ITestResult result = TestBuilder.RunTest(testMethod, fixture);

            Assert.That(result.ResultState, Is.EqualTo(ResultState.Cancelled));
            Assert.That(result.Children[0].ResultState, Is.EqualTo(ResultState.Success));
            Assert.That(result.Children[1].ResultState, Is.EqualTo(ResultState.Failure));
        }
        public void TestMethodWithMultipleTestCasesExecutesMultipleTimes()
        {
            Test test = TestFinder.Find("TestMethodWithMultipleTestCases", fixture, false);

            Assert.That(test.RunState, Is.EqualTo(RunState.Runnable));
            TestResult result = test.Run(NullListener.NULL, TestFilter.Empty);

            Assert.That(result.ResultState, Is.EqualTo(ResultState.Success));
            ResultSummarizer summary = new ResultSummarizer(result);

            Assert.That(summary.TestsRun, Is.EqualTo(3));
        }
Example #12
0
        public void TimeoutCanBeSetOnTestFixture()
        {
            ITestResult suiteResult = TestBuilder.RunTestFixture(typeof(TimeoutFixtureWithTimeoutOnFixture));

            Assert.That(suiteResult.ResultState, Is.EqualTo(ResultState.ChildFailure));
            Assert.That(suiteResult.Message, Is.EqualTo(TestResult.CHILD_ERRORS_MESSAGE));
            Assert.That(suiteResult.ResultState.Site, Is.EqualTo(FailureSite.Child));
            ITestResult result = TestFinder.Find("Test2WithInfiniteLoop", suiteResult, false);

            Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure));
            Assert.That(result.Message, Does.Contain("50ms"));
        }
        public void MethodWithParamsIsNamedCorrectly()
        {
            Test instance = (Test)fixture.Tests[0];
            Test method   = TestFinder.Find("MethodWithParams", instance, false);

            Assert.That(method, Is.Not.Null);

            Test testcase = (Test)method.Tests[0];

            Assert.That(testcase.TestName.Name, Is.EqualTo("MethodWithParams(10,20)"));
            Assert.That(testcase.TestName.FullName, Is.EqualTo(instance.TestName.FullName + ".MethodWithParams(10,20)"));
        }
        public void MultipleSuiteNameMatch()
        {
            testSuite.Add(TestBuilder.MakeFixture(typeof(OneTestCase)));
            NUnit.Core.TestSuite mockTestFixture    = (NUnit.Core.TestSuite)TestFinder.Find("MockTestFixture", testSuite, true);
            NUnit.Core.TestSuite oneTestCaseFixture = (NUnit.Core.TestSuite)TestFinder.Find("OneTestCase", testSuite, true);
            SimpleNameFilter     filter             = new SimpleNameFilter("NUnit.Tests.Assemblies.MockTestFixture,NUnit.Tests.Singletons.OneTestCase");

            Assert.IsTrue(filter.Pass(mock3), "Name Filter did not pass test case");
            Assert.IsTrue(filter.Pass(mockTestFixture), "Fixture did not pass test case");
            Assert.IsTrue(filter.Pass(oneTestCaseFixture), "Fixture did not pass test case");
            Assert.IsTrue(filter.Pass(testSuite), "Suite did not pass test case");
        }
Example #15
0
 public void SetUp()
 {
     _suite   = new TestSuite("TopLevelSuite");
     _fixture = TestBuilder.MakeFixture(typeof(MockTestFixture));
     _suite.Add(_fixture);
     _mock1        = TestFinder.Find("MockTest1", _fixture, false);
     _mock2        = TestFinder.Find("MockTest2", _fixture, false);
     _mock3        = TestFinder.Find("MockTest3", _fixture, false);
     _explicitTest = TestFinder.Find("ExplicitlyRunTest", _fixture, false);
     Assert.NotNull(_mock1, "MockTest1 not found");
     Assert.NotNull(_mock2, "MockTest2 not found");
     Assert.NotNull(_mock3, "MockTest3 not found");
 }
Example #16
0
        public void TestTimesOutAndTearDownIsRun()
        {
            TimeoutFixture fixture    = new TimeoutFixture();
            TestSuite      suite      = TestBuilder.MakeFixture(fixture);
            TestMethod     testMethod = (TestMethod)TestFinder.Find("InfiniteLoopWith50msTimeout", suite, false);
            ITestResult    result     = TestBuilder.RunTest(testMethod, fixture);

            Assert.That(result.ResultState.Status, Is.EqualTo(TestStatus.Failed));
            Assert.That(result.ResultState.Site, Is.EqualTo(FailureSite.Test));
            Assert.That(result.ResultState.Label, Is.EqualTo(result.Message));
            Assert.That(result.Message, Does.Contain("50ms"));
            Assert.That(fixture.TearDownWasRun, "TearDown was not run");
        }
Example #17
0
        public void CanIgnoreIndividualTestCases()
        {
            TestSuite suite = TestBuilder.MakeParameterizedMethodSuite(
                typeof(TestCaseSourceAttributeFixture), nameof(TestCaseSourceAttributeFixture.MethodWithIgnoredTestCases));

            Test testCase = TestFinder.Find("MethodWithIgnoredTestCases(1)", suite, false);

            Assert.That(testCase.RunState, Is.EqualTo(RunState.Runnable));

            testCase = TestFinder.Find("MethodWithIgnoredTestCases(2)", suite, false);
            Assert.That(testCase.RunState, Is.EqualTo(RunState.Ignored));
            Assert.That(testCase.Properties.Get(PropertyNames.SkipReason), Is.EqualTo("Don't Run Me!"));
        }
        public void RunExplicitTestByName()
        {
            Test test = TestFinder.Find("ExplicitlyRunTest", mockTestFixture, true);

            Assert.IsNotNull(test, "Cannot find ExplicitlyRunTest");
            Assert.AreEqual(RunState.Explicit, test.RunState);

            NameFilter       filter     = new NameFilter(test.TestName);
            TestResult       result     = mockTestFixture.Run(NullListener.NULL, filter);
            ResultSummarizer summarizer = new ResultSummarizer(result);

            Assert.AreEqual(1, summarizer.TestsRun);
        }
        public void DescriptionInResult()
        {
            TestSuite suite = new TestSuite("Mock Fixture");

            suite.Add(TestBuilder.MakeFixture(typeof(MockFixture)));
            TestResult result = suite.Run(NullListener.NULL, TestFilter.Empty);

            TestResult caseResult = TestFinder.Find("Method", result, true);

            Assert.AreEqual("Test Description", caseResult.Description);

            caseResult = TestFinder.Find("NoDescriptionMethod", result, true);
            Assert.IsNull(caseResult.Description);
        }
Example #20
0
        public void AssemblySetUpFixtureFollowsAssemblyNodeInTree()
        {
            IDictionary <string, object> options = new Dictionary <string, object>();
            var rootSuite = builder.Build(ASSEMBLY_PATH, options);

            Assert.That(rootSuite, Is.TypeOf <TestAssembly>());
            var setupFixture = rootSuite.Tests[0];

            Assert.That(setupFixture, Is.TypeOf <SetUpFixture>());

            var testFixture = TestFinder.Find("SomeFixture", (SetUpFixture)setupFixture, false);

            Assert.NotNull(testFixture);
            Assert.AreEqual(1, testFixture.Tests.Count);
        }
Example #21
0
        public void CanMarkIndividualTestCasesExplicit()
        {
            TestSuite suite = TestBuilder.MakeParameterizedMethodSuite(
                typeof(TestCaseAttributeFixture), "MethodWithExplicitTestCases");

            Test testCase = TestFinder.Find("MethodWithExplicitTestCases(1)", suite, false);

            Assert.That(testCase.RunState, Is.EqualTo(RunState.Runnable));

            testCase = TestFinder.Find("MethodWithExplicitTestCases(2)", suite, false);
            Assert.That(testCase.RunState, Is.EqualTo(RunState.Explicit));

            testCase = TestFinder.Find("MethodWithExplicitTestCases(3)", suite, false);
            Assert.That(testCase.RunState, Is.EqualTo(RunState.Explicit));
            Assert.That(testCase.Properties.Get(PropertyNames.SkipReason), Is.EqualTo("Connection failing"));
        }
Example #22
0
        public void RunTestsInFixture()
        {
            TestResult       result     = mockTestFixture.Run(NullListener.NULL);
            ResultSummarizer summarizer = new ResultSummarizer(result);

            Assert.AreEqual(MockTestFixture.Tests - MockTestFixture.NotRun, summarizer.ResultCount);
            Assert.AreEqual(MockTestFixture.Ignored, summarizer.TestsNotRun);

            result = TestFinder.Find("ExplicitlyRunTest", result);
            Assert.IsNull(result, "ExplicitlyRunTest should not be in results");

            // TODO: Decide if we want to include Explicitly run tests
            //			Assert.IsNotNull( result, "Cannot find ExplicitlyRunTest result" );
            //			Assert.IsFalse( result.Executed, "ExplicitlyRunTest should not be executed" );
            //			Assert.AreEqual( "Explicit selection required", result.Message );
        }
        public void CanMarkIndividualTestCasesExplicit()
        {
            Test test = TestBuilder.MakeTestCase(
                typeof(TestCaseSourceAttributeFixture), "MethodWithExplicitTestCases");

            Test testCase = TestFinder.Find("MethodWithExplicitTestCases(1)", test, false);

            Assert.That(testCase.RunState, Is.EqualTo(RunState.Runnable));

            testCase = TestFinder.Find("MethodWithExplicitTestCases(2)", test, false);
            Assert.That(testCase.RunState, Is.EqualTo(RunState.Explicit));

            testCase = TestFinder.Find("MethodWithExplicitTestCases(3)", test, false);
            Assert.That(testCase.RunState, Is.EqualTo(RunState.Explicit));
            Assert.That(testCase.IgnoreReason, Is.EqualTo("Connection failing"));
        }
        public void CanIgnoreIndividualTestCases()
        {
            Test test = TestBuilder.MakeTestCase(
                typeof(TestCaseSourceAttributeFixture), "MethodWithIgnoredTestCases");

            Test testCase = TestFinder.Find("MethodWithIgnoredTestCases(1)", test, false);

            Assert.That(testCase.RunState, Is.EqualTo(RunState.Runnable));

            testCase = TestFinder.Find("MethodWithIgnoredTestCases(2)", test, false);
            Assert.That(testCase.RunState, Is.EqualTo(RunState.Ignored));

            testCase = TestFinder.Find("MethodWithIgnoredTestCases(3)", test, false);
            Assert.That(testCase.RunState, Is.EqualTo(RunState.Ignored));
            Assert.That(testCase.IgnoreReason, Is.EqualTo("Don't Run Me!"));
        }
Example #25
0
        public void CanIgnoreIndividualTestCases()
        {
            TestSuite test = (TestSuite)TestBuilder.MakeTestCase(
                typeof(TestCaseSourceAttributeFixture), "MethodWithIgnoredTestCases");

            Test testCase = TestFinder.Find("MethodWithIgnoredTestCases(1)", test, false);

            Assert.That(testCase.RunState, Is.EqualTo(RunState.Runnable));

            testCase = TestFinder.Find("MethodWithIgnoredTestCases(2)", test, false);
            Assert.That(testCase.RunState, Is.EqualTo(RunState.Ignored));

            testCase = TestFinder.Find("MethodWithIgnoredTestCases(3)", test, false);
            Assert.That(testCase.RunState, Is.EqualTo(RunState.Ignored));
            Assert.That(testCase.Properties.GetSetting(PropertyNames.SkipReason, ""), Is.EqualTo("Don't Run Me!"));
        }
Example #26
0
        public void WhenResultIsCleared_IndexReflectsRunState(string testName, int expectedIndex)
        {
            Test       test   = TestFinder.Find(testName, testFixture, false);
            TestResult result = new TestResult(test);

            result.Failure("message", "stacktrace");

            TestSuiteTreeNode node = new TestSuiteTreeNode(result);

            Assert.AreEqual(TestSuiteTreeNode.FailureIndex, node.ImageIndex);
            Assert.AreEqual(TestSuiteTreeNode.FailureIndex, node.SelectedImageIndex);

            node.ClearResults();
            Assert.AreEqual(null, node.Result);
            Assert.AreEqual(expectedIndex, node.ImageIndex);
            Assert.AreEqual(expectedIndex, node.SelectedImageIndex);
        }
        public void RunTestsInFixture()
        {
            TestResult       result     = mockTestFixture.Run(NullListener.NULL, TestFilter.Empty);
            ResultSummarizer summarizer = new ResultSummarizer(result);

            Assert.AreEqual(MockTestFixture.TestsRun, summarizer.TestsRun, "TestsRun");
            Assert.AreEqual(MockTestFixture.NotRunnable, summarizer.NotRunnable, "NotRunnable");
            Assert.AreEqual(MockTestFixture.Ignored, summarizer.Ignored, "Ignored");
            Assert.AreEqual(MockTestFixture.Errors, summarizer.Errors, "Errors");
            Assert.AreEqual(MockTestFixture.Failures, summarizer.Failures, "Failures");

            result = TestFinder.Find("ExplicitlyRunTest", result, true);
            Assert.IsNull(result, "ExplicitlyRunTest should not be in results");

            // TODO: Decide if we want to include Explicit tests that are not run in results
            //			Assert.IsNotNull( result, "Cannot find ExplicitlyRunTest result" );
            //			Assert.IsFalse( result.Executed, "ExplicitlyRunTest should not be executed" );
            //			Assert.AreEqual( "Explicit selection required", result.Message );
        }
Example #28
0
        public void CanExcludePlatform()
        {
            bool isLinux = System.IO.Path.DirectorySeparatorChar == '/';

            TestSuite suite = TestBuilder.MakeParameterizedMethodSuite(
                typeof(TestCaseAttributeFixture), "MethodWitExcludePlatform");

            Test testCase1 = TestFinder.Find("MethodWitExcludePlatform(1)", suite, false);
            Test testCase2 = TestFinder.Find("MethodWitExcludePlatform(2)", suite, false);

            if (isLinux)
            {
                Assert.That(testCase1.RunState, Is.EqualTo(RunState.Runnable));
                Assert.That(testCase2.RunState, Is.EqualTo(RunState.Skipped));
            }
            else
            {
                Assert.That(testCase1.RunState, Is.EqualTo(RunState.Skipped));
                Assert.That(testCase2.RunState, Is.EqualTo(RunState.Runnable));
            }
        }
Example #29
0
        public void TestMethodWithMultipleTestCasesUsesCorrectNames()
        {
            string    name     = "TestMethodWithMultipleTestCases";
            string    fullName = typeof(TestMethodSignatureFixture).FullName + "." + name;
            TestSuite suite    = (TestSuite)TestFinder.Find(name, fixture, false);

            Assert.That(suite.TestCount, Is.EqualTo(3));
            suite.Sort();

            Test test = (Test)suite.Tests[0];

            Assert.That(test.TestName.Name, Is.EqualTo(name + "(12,2,6)"));
            Assert.That(test.TestName.FullName, Is.EqualTo(fullName + "(12,2,6)"));

            test = (Test)suite.Tests[1];
            Assert.That(test.TestName.Name, Is.EqualTo(name + "(12,3,4)"));
            Assert.That(test.TestName.FullName, Is.EqualTo(fullName + "(12,3,4)"));

            test = (Test)suite.Tests[2];
            Assert.That(test.TestName.Name, Is.EqualTo(name + "(12,4,3)"));
            Assert.That(test.TestName.FullName, Is.EqualTo(fullName + "(12,4,3)"));
        }
Example #30
0
        public void CanExcludeRuntime()
        {
            bool isNetCore;
            Type monoRuntimeType = Type.GetType("Mono.Runtime", false);
            bool isMono          = monoRuntimeType != null;

#if NETCOREAPP
            isNetCore = true;
#else
            isNetCore = false;
#endif

            const string methodName = nameof(TestCaseAttributeFixture.MethodWithExcludeRuntime);
            TestSuite    suite      = TestBuilder.MakeParameterizedMethodSuite(
                typeof(TestCaseAttributeFixture), methodName);

            Test testCase1 = TestFinder.Find($"{methodName}(1)", suite, false);
            Test testCase2 = TestFinder.Find($"{methodName}(2)", suite, false);
            Test testCase3 = TestFinder.Find($"{methodName}(3)", suite, false);
            if (isNetCore)
            {
                Assert.That(testCase1.RunState, Is.EqualTo(RunState.Runnable));
                Assert.That(testCase2.RunState, Is.EqualTo(RunState.Skipped));
                Assert.That(testCase3.RunState, Is.EqualTo(RunState.Runnable));
            }
            else if (isMono)
            {
                Assert.That(testCase1.RunState, Is.EqualTo(RunState.Runnable));
                Assert.That(testCase2.RunState, Is.EqualTo(RunState.Runnable));
                Assert.That(testCase3.RunState, Is.EqualTo(RunState.Skipped));
            }
            else
            {
                Assert.That(testCase1.RunState, Is.EqualTo(RunState.Skipped));
                Assert.That(testCase2.RunState, Is.EqualTo(RunState.Runnable));
                Assert.That(testCase3.RunState, Is.EqualTo(RunState.Runnable));
            }
        }