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_due_to_bad_methods.
@Test
void throws_could_not_invoke_step_when_execution_failed_due_to_bad_methods() {
Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have a data table\n" + " | A | \n" + " | B | \n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have a data table", new CucumberBackendException("This exception is expected!", new IllegalAccessException()), String.class, String.class);
List<Argument> arguments = asList(() -> "mocked table cell", () -> "mocked table cell");
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 a data table] defined at '{stubbed location with details}'.\n" + "It appears there was a problem with the step definition.\n" + "The converted arguments types were (java.lang.String, java.lang.String)")));
}
use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments.
@Test
void throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have 4 cukes in my belly\n" + " | A | B | \n" + " | C | D | \n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have {int} cukes in my belly", Integer.TYPE, Short.TYPE, List.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
PickleStepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Step [I have {int} cukes in my belly] is defined with 3 parameters at '{stubbed location with details}'.\n" + "However, the gherkin step has 2 arguments:\n" + " * 4\n" + " * Table:\n" + " | A | B |\n" + " | C | D |\n" + "\n" + "Step text: I have 4 cukes in my belly")));
}
use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class RuntimeTest method should_call_formatter_for_scenario_outline_with_two_examples_table_and_background.
@Test
void should_call_formatter_for_scenario_outline_with_two_examples_table_and_background() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + " Background: background\n" + " Given first step\n" + " Scenario Outline: scenario outline name\n" + " When <x> step\n" + " Then <y> step\n" + " Examples: examples 1 name\n" + " | x | y |\n" + " | second | third |\n" + " | second | third |\n" + " Examples: examples 2 name\n" + " | x | y |\n" + " | second | third |\n");
FormatterSpy formatterSpy = new FormatterSpy();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(formatterSpy).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).build().run();
assertThat(formatterSpy.toString(), is(equalTo("" + "TestRun started\n" + " TestCase started\n" + " TestStep started\n" + " TestStep finished\n" + " TestStep started\n" + " TestStep finished\n" + " TestStep started\n" + " TestStep finished\n" + " TestCase finished\n" + " TestCase started\n" + " TestStep started\n" + " TestStep finished\n" + " TestStep started\n" + " TestStep finished\n" + " TestStep started\n" + " TestStep finished\n" + " TestCase finished\n" + " TestCase started\n" + " TestStep started\n" + " TestStep finished\n" + " TestStep started\n" + " TestStep finished\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_fail_on_event_listener_exception_when_running_in_parallel.
@Test
void should_fail_on_event_listener_exception_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");
ConcurrentEventListener brokenEventListener = publisher -> publisher.registerHandlerFor(TestStepFinished.class, (TestStepFinished event) -> {
throw new RuntimeException("This exception is expected");
});
Executable testMethod = () -> Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2)).withAdditionalPlugins(brokenEventListener).withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(2).build()).build().run();
CompositeCucumberException actualThrown = assertThrows(CompositeCucumberException.class, testMethod);
assertThat(actualThrown.getMessage(), is(equalTo("There were 3 exceptions. The details are in the stacktrace below.")));
assertThat(actualThrown.getSuppressed(), is(arrayWithSize(3)));
}
use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class RuntimeTest method should_call_formatter_for_two_scenarios_with_background.
@Test
void should_call_formatter_for_two_scenarios_with_background() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + " Background: background\n" + " Given first step\n" + " Scenario: scenario_1 name\n" + " When second step\n" + " Then third step\n" + " Scenario: scenario_2 name\n" + " Then second step\n");
FormatterSpy formatterSpy = new FormatterSpy();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(formatterSpy).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).build().run();
assertThat(formatterSpy.toString(), is(equalTo("" + "TestRun started\n" + " TestCase started\n" + " TestStep started\n" + " TestStep finished\n" + " TestStep started\n" + " TestStep finished\n" + " TestStep started\n" + " TestStep finished\n" + " TestCase finished\n" + " TestCase started\n" + " TestStep started\n" + " TestStep finished\n" + " TestStep started\n" + " TestStep finished\n" + " TestCase finished\n" + "TestRun finished\n")));
}
Aggregations