Search in sources :

Example 11 with HookDefinition

use of io.cucumber.core.backend.HookDefinition in project cucumber-jvm by cucumber.

the class RuntimeTest method should_make_scenario_name_available_to_hooks.

@Test
void should_make_scenario_name_available_to_hooks() {
    final Feature feature = TestFeatureParser.parse("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    When second step\n" + "    Then third step\n");
    final HookDefinition beforeHook = mock(HookDefinition.class);
    when(beforeHook.getLocation()).thenReturn("");
    when(beforeHook.getTagExpression()).thenReturn("");
    FeatureSupplier featureSupplier = new StubFeatureSupplier(feature);
    Runtime runtime = Runtime.builder().withFeatureSupplier(featureSupplier).withBackendSupplier(new StubBackendSupplier(singletonList(beforeHook), asList(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step")), emptyList())).build();
    runtime.run();
    ArgumentCaptor<TestCaseState> capturedScenario = ArgumentCaptor.forClass(TestCaseState.class);
    verify(beforeHook).execute(capturedScenario.capture());
    assertThat(capturedScenario.getValue().getName(), is(equalTo("scenario name")));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Feature(io.cucumber.core.gherkin.Feature) HookDefinition(io.cucumber.core.backend.HookDefinition) TestCaseState(io.cucumber.core.backend.TestCaseState) Test(org.junit.jupiter.api.Test)

Example 12 with HookDefinition

use of io.cucumber.core.backend.HookDefinition in project cucumber-jvm by cucumber.

the class RunnerTest method steps_are_skipped_after_failure.

@Test
void steps_are_skipped_after_failure() {
    StubStepDefinition stepDefinition = spy(new StubStepDefinition("some step"));
    Pickle pickleMatchingStepDefinitions = createPickleMatchingStepDefinitions(stepDefinition);
    final HookDefinition failingBeforeHook = createHook();
    doThrow(new RuntimeException("Boom")).when(failingBeforeHook).execute(ArgumentMatchers.any());
    TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            glue.addBeforeHook(failingBeforeHook);
            glue.addStepDefinition(stepDefinition);
        }
    };
    runnerSupplier.get().runPickle(pickleMatchingStepDefinitions);
    InOrder inOrder = inOrder(failingBeforeHook, stepDefinition);
    inOrder.verify(failingBeforeHook).execute(any(TestCaseState.class));
    inOrder.verify(stepDefinition, never()).execute(any(Object[].class));
}
Also used : Pickle(io.cucumber.core.gherkin.Pickle) InOrder(org.mockito.InOrder) Glue(io.cucumber.core.backend.Glue) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) StaticHookDefinition(io.cucumber.core.backend.StaticHookDefinition) HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Example 13 with HookDefinition

use of io.cucumber.core.backend.HookDefinition in project cucumber-jvm by cucumber.

the class RunnerTest method aftersteps_are_executed_after_failed_step.

@Test
void aftersteps_are_executed_after_failed_step() {
    StubStepDefinition stepDefinition = spy(new StubStepDefinition("some step") {

        @Override
        public void execute(Object[] args) {
            super.execute(args);
            throw new RuntimeException();
        }
    });
    Pickle pickleMatchingStepDefinitions = createPickleMatchingStepDefinitions(stepDefinition);
    final HookDefinition afterStepHook = createHook();
    TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            glue.addAfterHook(afterStepHook);
            glue.addStepDefinition(stepDefinition);
        }
    };
    runnerSupplier.get().runPickle(pickleMatchingStepDefinitions);
    InOrder inOrder = inOrder(afterStepHook, stepDefinition);
    inOrder.verify(stepDefinition).execute(any(Object[].class));
    inOrder.verify(afterStepHook).execute(any(TestCaseState.class));
}
Also used : Pickle(io.cucumber.core.gherkin.Pickle) InOrder(org.mockito.InOrder) Glue(io.cucumber.core.backend.Glue) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) StaticHookDefinition(io.cucumber.core.backend.StaticHookDefinition) HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Example 14 with HookDefinition

use of io.cucumber.core.backend.HookDefinition in project cucumber-jvm by cucumber.

the class RunnerTest method createHook.

private HookDefinition createHook() {
    HookDefinition hook = mock(HookDefinition.class);
    when(hook.getTagExpression()).thenReturn("");
    when(hook.getLocation()).thenReturn("");
    return hook;
}
Also used : StaticHookDefinition(io.cucumber.core.backend.StaticHookDefinition) HookDefinition(io.cucumber.core.backend.HookDefinition)

Example 15 with HookDefinition

use of io.cucumber.core.backend.HookDefinition in project cucumber-jvm by cucumber.

the class RunnerTest method aftersteps_executed_for_passed_step.

@Test
void aftersteps_executed_for_passed_step() {
    StubStepDefinition stepDefinition = spy(new StubStepDefinition("some step"));
    Pickle pickle = createPickleMatchingStepDefinitions(stepDefinition);
    HookDefinition afteStepHook1 = createHook();
    HookDefinition afteStepHook2 = createHook();
    TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            glue.addAfterHook(afteStepHook1);
            glue.addAfterHook(afteStepHook2);
            glue.addStepDefinition(stepDefinition);
        }
    };
    runnerSupplier.get().runPickle(pickle);
    InOrder inOrder = inOrder(afteStepHook1, afteStepHook2, stepDefinition);
    inOrder.verify(stepDefinition).execute(any(Object[].class));
    inOrder.verify(afteStepHook2).execute(any(TestCaseState.class));
    inOrder.verify(afteStepHook1).execute(any(TestCaseState.class));
}
Also used : Pickle(io.cucumber.core.gherkin.Pickle) InOrder(org.mockito.InOrder) Glue(io.cucumber.core.backend.Glue) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) StaticHookDefinition(io.cucumber.core.backend.StaticHookDefinition) HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

HookDefinition (io.cucumber.core.backend.HookDefinition)20 Test (org.junit.jupiter.api.Test)18 Glue (io.cucumber.core.backend.Glue)14 List (java.util.List)11 InOrder (org.mockito.InOrder)11 StaticHookDefinition (io.cucumber.core.backend.StaticHookDefinition)8 ArrayList (java.util.ArrayList)6 Collections.emptyList (java.util.Collections.emptyList)6 Collections.singletonList (java.util.Collections.singletonList)6 Backend (io.cucumber.core.backend.Backend)3 ObjectFactory (io.cucumber.core.backend.ObjectFactory)3 Pickle (io.cucumber.core.gherkin.Pickle)3 TestSnippet (io.cucumber.core.snippets.TestSnippet)3 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)2 TestCaseState (io.cucumber.core.backend.TestCaseState)1 Feature (io.cucumber.core.gherkin.Feature)1 RuntimeOptions (io.cucumber.core.options.RuntimeOptions)1 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)1