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")));
}
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));
}
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));
}
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;
}
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));
}
Aggregations