Exemplo n.º 1
0
        public void GetTestRunner_should_return_different_instances_when_executed_by_different_threads()
        {
            //This test can't run in NCrunch as when NCrunch runs the tests it will disable the ability to get different test runners for each thread
            //as it manages the parallelisation
            //see https://github.com/techtalk/SpecFlow/issues/638
            if (!TestEnvironmentHelper.IsBeingRunByNCrunch())
            {
                ITestRunner testRunner1 = null;
                ITestRunner testRunner2 = null;
                var         thread1     = new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    testRunner1 = TestRunnerManager.GetTestRunner();
                });


                var thread2 = new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    /* run your code here */
                    testRunner2 = TestRunnerManager.GetTestRunner();
                });
                thread1.Start();
                thread2.Start();

                thread1.Join();
                thread2.Join();
                Assert.IsNotNull(testRunner1);
                Assert.IsNotNull(testRunner2);
                Assert.AreNotEqual(testRunner1, testRunner2);
            }
        }
        public async Task Should_resolve_a_test_runner_specific_test_tracer()
        {
            //This test can't run in NCrunch as when NCrunch runs the tests it will disable the ability to get different test runners for each thread
            //as it manages the parallelisation
            //see https://github.com/techtalk/SpecFlow/issues/638
            if (!TestEnvironmentHelper.IsBeingRunByNCrunch())
            {
                var testRunner1 = await TestRunnerManager.GetTestRunnerAsync(nameof(TestRunnerManagerRunnerCreationTests) + "_0", anAssembly, new RuntimeTestsContainerBuilder());

                await testRunner1.OnFeatureStartAsync(new FeatureInfo(new CultureInfo("en-US"), "sds", "sss"));

                testRunner1.OnScenarioInitialize(new ScenarioInfo("foo", "foo_desc"));
                await testRunner1.OnScenarioStartAsync();

                var tracer1 = testRunner1.ScenarioContext.ScenarioContainer.Resolve <ITestTracer>();

                var testRunner2 = await TestRunnerManager.GetTestRunnerAsync(nameof(TestRunnerManagerRunnerCreationTests) + "_1", anAssembly, new RuntimeTestsContainerBuilder());

                await testRunner2.OnFeatureStartAsync(new FeatureInfo(new CultureInfo("en-US"), "sds", "sss"));

                testRunner2.OnScenarioInitialize(new ScenarioInfo("foo", "foo_desc"));
                await testRunner1.OnScenarioStartAsync();

                var tracer2 = testRunner2.ScenarioContext.ScenarioContainer.Resolve <ITestTracer>();

                tracer1.Should().NotBeSameAs(tracer2);
            }
        }
        public void Should_resolve_a_test_runner_specific_test_tracer()
        {
            //This test can't run in NCrunch as when NCrunch runs the tests it will disable the ability to get different test runners for each thread
            //as it manages the parallelisation
            //see https://github.com/techtalk/SpecFlow/issues/638
            if (!TestEnvironmentHelper.IsBeingRunByNCrunch())
            {
                var testRunner1 = TestRunnerManager.GetTestRunner(anAssembly, 0);
                testRunner1.OnFeatureStart(new FeatureInfo(new CultureInfo("en-US"), "sds", "sss"));
                testRunner1.OnScenarioStart(new ScenarioInfo("foo"));
                var tracer1 = testRunner1.ScenarioContext.ScenarioContainer.Resolve <ITestTracer>();

                var testRunner2 = TestRunnerManager.GetTestRunner(anAssembly, 1);
                testRunner2.OnFeatureStart(new FeatureInfo(new CultureInfo("en-US"), "sds", "sss"));
                testRunner2.OnScenarioStart(new ScenarioInfo("foo"));
                var tracer2 = testRunner2.ScenarioContext.ScenarioContainer.Resolve <ITestTracer>();

                tracer1.Should().NotBeSameAs(tracer2);
            }
        }