use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class RuntimeTest method generates_events_for_glue_and_scenario_scoped_glue.
@Test
void generates_events_for_glue_and_scenario_scoped_glue() {
final Feature feature = TestFeatureParser.parse("test.feature", "" + "Feature: feature name\n" + " Scenario: Run a scenario once\n" + " Given global scoped\n" + " And scenario scoped\n" + " Scenario: Then do it again\n" + " Given global scoped\n" + " And scenario scoped\n" + "");
final List<StepDefinition> stepDefinedEvents = new ArrayList<>();
Plugin eventListener = (EventListener) publisher -> publisher.registerHandlerFor(StepDefinedEvent.class, (StepDefinedEvent event) -> {
stepDefinedEvents.add(event.getStepDefinition());
});
final MockedStepDefinition mockedStepDefinition = new MockedStepDefinition();
final MockedScenarioScopedStepDefinition mockedScenarioScopedStepDefinition = new MockedScenarioScopedStepDefinition();
BackendSupplier backendSupplier = new TestBackendSupplier() {
private Glue glue;
@Override
public void loadGlue(Glue glue, List<URI> gluePaths) {
this.glue = glue;
glue.addStepDefinition(mockedStepDefinition);
}
@Override
public void buildWorld() {
glue.addStepDefinition(mockedScenarioScopedStepDefinition);
}
};
FeatureSupplier featureSupplier = new StubFeatureSupplier(feature);
Runtime.builder().withBackendSupplier(backendSupplier).withAdditionalPlugins(eventListener).withEventBus(new TimeServiceEventBus(new StepDurationTimeService(ZERO), UUID::randomUUID)).withFeatureSupplier(featureSupplier).build().run();
assertThat(stepDefinedEvents.get(0).getPattern(), is(mockedStepDefinition.getPattern()));
assertThat(stepDefinedEvents.get(1).getPattern(), is(mockedScenarioScopedStepDefinition.getPattern()));
// Twice, once for each scenario
assertThat(stepDefinedEvents.get(2).getPattern(), is(mockedStepDefinition.getPattern()));
assertThat(stepDefinedEvents.get(3).getPattern(), is(mockedScenarioScopedStepDefinition.getPattern()));
assertThat(stepDefinedEvents.size(), is(4));
}
use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class RuntimeTest method should_interrupt_waiting_plugins.
@Test
void should_interrupt_waiting_plugins() throws InterruptedException {
final Feature feature1 = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name 1\n" + " Scenario: scenario_1 name\n" + " Given first step\n" + " Scenario: scenario_2 name\n" + " Given first step\n");
final Feature feature2 = TestFeatureParser.parse("path/test2.feature", "" + "Feature: feature name 2\n" + " Scenario: scenario_2 name\n" + " Given first step\n");
final CountDownLatch threadBlocked = new CountDownLatch(1);
final CountDownLatch interruptHit = new CountDownLatch(1);
final ConcurrentEventListener brokenEventListener = publisher -> publisher.registerHandlerFor(TestStepFinished.class, (TestStepFinished event) -> {
try {
threadBlocked.countDown();
HOURS.sleep(1);
} catch (InterruptedException ignored) {
interruptHit.countDown();
}
});
Thread thread = new Thread(() -> Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2)).withAdditionalPlugins(brokenEventListener).withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(2).build()).build().run());
thread.start();
threadBlocked.await(1, SECONDS);
thread.interrupt();
interruptHit.await(1, SECONDS);
assertThat(interruptHit.getCount(), is(equalTo(0L)));
}
use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class RuntimeTest method should_call_formatter_with_correct_sequence_of_events_when_running_in_parallel.
@Test
void should_call_formatter_with_correct_sequence_of_events_when_running_in_parallel() {
Feature feature1 = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name 1\n" + " Scenario: scenario_1 name\n" + " Given first step\n" + " Scenario: scenario_2 name\n" + " Given first step\n");
Feature feature2 = TestFeatureParser.parse("path/test2.feature", "" + "Feature: feature name 2\n" + " Scenario: scenario_2 name\n" + " Given first step\n");
Feature feature3 = TestFeatureParser.parse("path/test3.feature", "" + "Feature: feature name 3\n" + " Scenario: scenario_3 name\n" + " Given first step\n");
FormatterSpy formatterSpy = new FormatterSpy();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2, feature3)).withAdditionalPlugins(formatterSpy).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step"))).withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(3).build()).build().run();
String formatterOutput = formatterSpy.toString();
assertThat(formatterOutput, is(equalTo("" + "TestRun started\n" + " TestCase started\n" + " TestStep started\n" + " TestStep finished\n" + " TestCase finished\n" + " TestCase started\n" + " TestStep started\n" + " TestStep finished\n" + " TestCase finished\n" + " TestCase started\n" + " TestStep started\n" + " TestStep finished\n" + " TestCase finished\n" + " TestCase started\n" + " TestStep started\n" + " TestStep finished\n" + " TestCase finished\n" + "TestRun finished\n")));
}
use of io.cucumber.core.gherkin.Feature 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.gherkin.Feature in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_invoke_step_when_execution_failed_with_null_arguments.
@Test
void throws_could_not_invoke_step_when_execution_failed_with_null_arguments() {
Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have an null value\n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have an {word} value", new CucumberBackendException("This exception is expected!", new IllegalAccessException()), String.class);
List<Argument> arguments = asList(() -> null);
StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, URI.create("file:path/to.feature"), step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not invoke step [I have an {word} value] defined at '{stubbed location with details}'.\n" + "It appears there was a problem with the step definition.\n" + "The converted arguments types were (null)")));
}
Aggregations