コード例 #1
0
        public void TestRunTestsAsyncWithAssemblyRunsTestsAndReturnsTheRanTests([Values] bool withChildTests,
                                                                                [Values] bool withListener, [Values] bool withFilter)
        {
            ITestFilter filter = withFilter
                ? NUnitFilter.Where.Class(typeof(TestFixtureStubOne).FullName).And.Method("Test2").Build().Filter
                : null;
            ResultState expectedState = ResultState.Inconclusive;

            if (withChildTests)
            {
                expectedState = withFilter ? ResultState.Success : ResultState.ChildFailure;
            }

            TestListenerForTest listener = withListener ? new TestListenerForTest() : null;

            INUnitRunner runner   = new NUnitRunner("suite-name");
            Assembly     assembly = typeof(TestFixtureStubOne).Assembly;

            int expectedCaseCount   = 0;
            int expectedResultCount = 0;

            if (withChildTests)
            {
                expectedCaseCount = TestFixtureStubHelper.GeTestFixtureStub().ResultsDepth +
                                    (withFilter ? 2 : TestFixtureStubHelper.GeTestFixtureStub().ResultCount);
                expectedResultCount = withFilter ? 1 : TestFixtureStubHelper.GeTestFixtureStub().TestCount;
                Task <ITest> testTask = runner.AddTestAssemblyAsync(assembly);
                testTask.Wait();
            }

            Task <ITestResult> testsTask = runner.RunTestsAsync(assembly, listener, filter);

            Assert.IsNotNull(testsTask);
            testsTask.Wait();
            ITestResult results = testsTask.Result;

            if (withChildTests)
            {
                Assert.IsNotNull(results);
                Assert.IsFalse(runner.IsTestRunning);
                Assert.IsTrue(runner.IsTestComplete);
                Assert.AreEqual(expectedState, results.ResultState);
                int totalResultCount = results.FailCount + results.InconclusiveCount + results.PassCount +
                                       results.SkipCount +
                                       results.WarningCount;
                Assert.AreEqual(expectedResultCount, totalResultCount);

                if (withListener)
                {
                    Assert.AreEqual(expectedCaseCount, listener.Tests.Count);
                }
            }
            else
            {
                Assert.IsNull(results);
            }
        }
コード例 #2
0
        TestRunTestsAsyncWithAlreadyRunningTestWaitsForPreviousCompletionAndThenRunsTestsAndReturnsTheRanTests()
        {
            TestListenerForTest listener = new TestListenerForTest();

            NUnitSuiteForTest         suite          = new NUnitSuiteForTest("suite-name");
            TestAssemblyRunnerForTest assemblyRunner = new TestAssemblyRunnerForTest();

            assemblyRunner.IsTestLoaded  = true;
            assemblyRunner.IsTestRunning = true;
            suite.RunnerToLoad           = assemblyRunner;

            NUnitRunnerForTest runner   = new NUnitRunnerForTest(suite);
            Assembly           assembly = typeof(TestFixtureStubOne).Assembly;

            int expectedCaseCount = TestFixtureStubHelper.GeTestFixtureStub().ResultsDepth +
                                    TestFixtureStubHelper.GeTestFixtureStub().ResultCount;
            int          expectedResultCount = TestFixtureStubHelper.GeTestFixtureStub().TestCount;
            Task <ITest> testTask            = runner.AddTestAssemblyAsync(assembly);

            testTask.Wait();

            Assert.IsTrue(runner.IsTestRunning);
            Assert.IsFalse(runner.IsTestComplete);

            Task <ITestResult> testsTask = runner.RunTestsAsync(listener);

            Assert.IsNotNull(testsTask);
            Assert.IsTrue(runner.IsTestRunning);
            Assert.IsFalse(runner.IsTestComplete);

            Thread.Sleep(50);
            assemblyRunner.IsTestRunning = false;

            testsTask.Wait();
            ITestResult results = testsTask.Result;

            Assert.IsFalse(runner.IsTestRunning);
            Assert.IsTrue(runner.IsTestComplete);

            Assert.IsNotNull(results);
            Assert.IsFalse(runner.IsTestRunning);
            Assert.IsTrue(runner.IsTestComplete);
            Assert.AreEqual(ResultState.ChildFailure, results.ResultState);
            int totalResultCount = results.FailCount + results.InconclusiveCount + results.PassCount +
                                   results.SkipCount +
                                   results.WarningCount;

            Assert.AreEqual(expectedResultCount, totalResultCount);
            Assert.AreEqual(expectedCaseCount, listener.Tests.Count);
        }