Exemple #1
0
        public void It_should_capture_scenario_name_with_global_categories()
        {
            _runner.Test().TestScenario(Some_step);
            var scenario = _feature.GetFeatureResult().GetScenarios().Single();

            Assert.That(scenario.Info.Categories, Is.EqualTo(new[] { "global1", "global2" }));
        }
        public void Runner_should_instantiate_scenario_context_within_scenario_scope()
        {
            _runner.Test()
            .WithContext(r => r.Resolve <MyScenarioScope>())
            .TestScenario(Given_step_one);

            _containerScope.Verify(s => s.BeginScope(LifetimeScope.Scenario, It.IsAny <Action <ContainerConfigurator> >()));
            _scenarioScope.Verify(s => s.Resolve(typeof(MyScenarioScope)));
        }
        public void Runner_should_execute_all_steps()
        {
            _runner.Test().TestScenario(
                Given_step_one,
                When_step_two,
                Then_step_three);

            Assert.That(_executedSteps, Is.EqualTo(new[] { "Given_step_one", "When_step_two", "Then_step_three" }));
        }
Exemple #4
0
        public void Runner_should_instantiate_context_just_before_run_so_its_failure_would_be_included_in_results()
        {
            Assert.Throws <InvalidOperationException>(() => _runner.Test()
                                                      .WithContext(() => { throw new InvalidOperationException("abc"); })
                                                      .TestScenario(Given_step_one));

            var scenario = _feature.GetFeatureResult().GetScenarios().Single();

            Assert.That(scenario.Status, Is.EqualTo(ExecutionStatus.Failed));
            Assert.That(scenario.StatusDetails, Is.EqualTo("Context initialization failed: abc"));
        }
Exemple #5
0
        public void Runner_should_await_for_async_void_step_before_calling_next_one()
        {
            var    finished = false;
            Action step1    = async() =>
            {
                await Task.Delay(200);

                finished = true;
            };

            Action step2 = () => Assert.True(finished);

            Assert.DoesNotThrow(() => _runner.Test().TestScenario(step1, step2));
        }
Exemple #6
0
        public void It_should_execute_all_the_steps_in_same_thread_as_scenario()
        {
            var currentThreadId = Thread.CurrentThread.ManagedThreadId;
            var stepThreadIds   = new List <int>();

            var steps = Enumerable
                        .Repeat <Action>(() => stepThreadIds.Add(Thread.CurrentThread.ManagedThreadId), 500)
                        .ToArray();

            _runner.Test().TestScenarioPurelySync(steps);

            Assert.That(stepThreadIds.Count, Is.EqualTo(steps.Length), "Not all steps were executed");
            Assert.That(stepThreadIds.Distinct().ToArray(), Is.EqualTo(new[] { currentThreadId }), "All steps should be executed within same thread as scenario");
        }
Exemple #7
0
        public void It_should_capture_all_steps()
        {
            _runner.Test().TestScenario(
                Given_step_one,
                When_step_two,
                Then_step_three);

            var steps = _feature.GetFeatureResult().GetScenarios().Single().GetSteps();

            StepResultExpectation.AssertEqual(steps,
                                              new StepResultExpectation(1, 3, "GIVEN step one", ExecutionStatus.Passed),
                                              new StepResultExpectation(2, 3, "WHEN step two", ExecutionStatus.Passed),
                                              new StepResultExpectation(3, 3, "THEN step three", ExecutionStatus.Passed)
                                              );
        }
Exemple #8
0
        public void Execution_results_should_print_user_friendly_output()
        {
            try
            {
                _runner.Test().TestScenario(
                    Given_step_one,
                    When_step_two,
                    Then_step_three);
            }
            catch { }

            var featureResult = _feature.GetFeatureResult();

            Assert.That(featureResult.ToString(), Is.EqualTo("[Ticket-1][Ticket-2] FeatureFixtureRunner execution results tests"));

            var scenarioResult = featureResult.GetScenarios().Single();

            Assert.That(scenarioResult.ToString(), Is.EqualTo("[Label-1][Label-2] Execution results should print user friendly output: Failed (Step 3: reason)"));

            Assert.That(scenarioResult.GetSteps().Select(s => s.ToString()).ToArray(), Is.EqualTo(new[]
            {
                "1/3 GIVEN step one: Passed",
                "2/3 WHEN step two: Passed",
                "3/3 THEN step three: Failed (Step 3: reason)"
            }));
        }
        public void Runner_should_call_steps_with_parameters()
        {
            _runner.Test().TestScenario(
                TestStep.CreateAsync(Given_step_one, "abc"),
                TestStep.CreateAsync(When_step_two, 123),
                TestStep.CreateAsync(Then_step_three, 3.25));

            var expected = new[]
            {
                Tuple.Create("Given_step_one", (object)"abc"),
                Tuple.Create("When_step_two", (object)123),
                Tuple.Create("Then_step_three", (object)3.25)
            };

            Assert.That(_executedSteps, Is.EqualTo(expected));
        }
        public void It_should_capture_scenario_name()
        {
            _runner.Test().TestScenario(Some_step);
            var scenario = _feature.GetFeatureResult().GetScenarios().Single();

            Assert.That(scenario.Info.Name.ToString(), Is.EqualTo("It should capture scenario name"));
            Assert.That(scenario.Info.Labels, Is.Empty);
            Assert.That(scenario.Info.Categories, Is.Empty);
        }
Exemple #11
0
        public void Invalid_step_descriptors_should_make_scenario_failing_immediately_without_execution()
        {
            var step1 = TestStep.Create(Step_that_should_not_run);
            var step2 = StepDescriptor.CreateInvalid(new Exception("reason1"));
            var step3 = StepDescriptor.CreateInvalid(new Exception("reason2"));
            var ex    = Assert.Throws <AggregateException>(() => _runner.Test().TestScenario(step1, step2, step3));

            Assert.That(ex.InnerExceptions.Select(x => x.Message).ToArray(),
                        Is.EqualTo(new[] { "Scenario steps initialization failed.", "reason1", "reason2" }));

            var steps = _feature.GetFeatureResult().GetScenarios().Single().GetSteps();

            StepResultExpectation.AssertEqual(steps,
                                              new StepResultExpectation(1, 3, "Step that should not run", ExecutionStatus.NotRun),
                                              new StepResultExpectation(2, 3, "<INVALID STEP>", ExecutionStatus.Failed, "Step 2: reason1"),
                                              new StepResultExpectation(3, 3, "<INVALID STEP>", ExecutionStatus.Failed, "Step 3: reason2"));
        }
Exemple #12
0
        public async Task It_should_support_asynchronous_processing_up_to_step_level()
        {
            var semaphore   = new SemaphoreSlim(0);
            var stepEntered = false;

            var scenarioTask = _runner.Test().TestScenarioAsync(async() =>
            {
                stepEntered = true;
                if (!await semaphore.WaitAsync(TimeSpan.FromSeconds(3)))
                {
                    throw new InvalidOperationException("Await failed");
                }
            });

            Assert.That(stepEntered, Is.True);
            semaphore.Release();
            await scenarioTask;
        }
Exemple #13
0
        private void Parallel_scenario(int idx)
        {
            var steps = new[]
            {
                TestStep.CreateAsync(Given_step_with_parameter, idx.ToString()),
                TestStep.CreateAsync(When_step_with_parameter_and_comments, idx),
                TestStep.CreateAsync(Then_step_with_parameter, (double)idx)
            };

            _runner.Test().TestNamedScenario($"Parallel scenario \"{idx}\"", steps);
        }
        public void Runner_should_call_steps_with_parameters()
        {
            _runner.Test().TestScenario(
                TestStep.CreateAsync(Given_step_one, "abc"),
                TestStep.CreateAsync(When_step_two, 123),
                TestStep.CreateAsync(Then_step_three, 3.25),
                TestStep.CreateAsync(Then_another_step, (double?)3.25),
                TestStep.CreateAsync(Then_another_step, (double?)null));

            var expected = new[]
            {
                Tuple.Create(nameof(Given_step_one), (object)"abc"),
                Tuple.Create(nameof(When_step_two), (object)123),
                Tuple.Create(nameof(Then_step_three), (object)3.25),
                Tuple.Create(nameof(Then_another_step), (object)3.25),
                Tuple.Create(nameof(Then_another_step), (object)null)
            };

            Assert.That(_executedSteps, Is.EqualTo(expected));
        }
Exemple #15
0
        public void It_should_capture_all_steps()
        {
            _runner.Test().TestScenario(
                TestStep.CreateAsync(Given_step_with_parameter, "abc"),
                TestStep.CreateAsync(When_step_with_parameter, 123),
                TestStep.CreateAsync(Then_step_with_parameter, 3.15));

            var steps = _feature.GetFeatureResult().GetScenarios().Single().GetSteps();

            StepResultExpectation.AssertEqual(steps,
                                              new StepResultExpectation(1, 3, "GIVEN step with parameter \"abc\"", ExecutionStatus.Passed),
                                              new StepResultExpectation(2, 3, "WHEN step with parameter \"123\"", ExecutionStatus.Passed),
                                              new StepResultExpectation(3, 3, "THEN step with parameter \"3.15\"", ExecutionStatus.Passed)
                                              );
        }
Exemple #16
0
        public void Runner_should_capture_details_about_sub_step_initialization_failure()
        {
            Assert.Throws <InvalidOperationException>(() => _runner.Test().TestGroupScenario(Incorrect_step_group));
            var steps = _feature.GetFeatureResult().GetScenarios().Single().GetSteps().ToArray();

            StepResultExpectation.AssertEqual(steps,
                                              new StepResultExpectation(1, 1, "Incorrect step group", ExecutionStatus.Failed, "Step 1: Sub-steps initialization failed: abc"));
        }
 public void It_should_capture_execution_time_for_successful_scenario()
 {
     AssertScenarioExecutionTime(() => _runner.Test().TestScenario(Step_one, Step_two));
 }
 public void Runner_should_throw_only_first_ignore_exception_to_be_properly_handled_by_underlying_testing_framework()
 {
     Assert.Throws <CustomIgnoreException>(() => _runner.Test().TestGroupScenario(Multiassert_ignoring_steps));
 }