use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method rethrows_target_invocation_exceptions_from_data_table.
@Test
void rethrows_target_invocation_exceptions_from_data_table() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some cukes in my belly\n" + " | 3 | \n" + " | 14 | \n" + " | 15 | \n");
RuntimeException userException = new RuntimeException();
stepTypeRegistry.defineDataTableType(new DataTableType(ItemQuantity.class, (String cell) -> {
throw new CucumberInvocationTargetException(stubbedLocation, new InvocationTargetException(userException));
}));
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have some cukes in my belly", ItemQuantity.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
RuntimeException actualThrown = assertThrows(RuntimeException.class, testMethod);
assertThat(actualThrown, sameInstance(userException));
}
use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method testScenarioWithFailedAfterHook.
@Test
void testScenarioWithFailedAfterHook() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature\n" + " Scenario: scenario\n" + " When step\n" + " Then step\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new TestNGFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(emptyList(), singletonList(new StubStepDefinition("step")), singletonList(new StubHookDefinition(new StubException("message", "stacktrace"))))).build().run();
String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\">" + " <suite name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"0\">" + " <test name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"0\">" + " <class name=\"feature\">" + " <test-method name=\"scenario\" status=\"FAIL\" duration-ms=\"0\" started-at=\"1970-01-01T00:00:00Z\" finished-at=\"1970-01-01T00:00:00Z\">" + " <exception class=\"io.cucumber.core.plugin.StubException\">" + " <message><![CDATA[When step...................................................................passed\n" + "Then step...................................................................passed\n" + "]]></message>" + " <full-stacktrace><![CDATA[stacktrace]]></full-stacktrace>" + " </exception>" + " </test-method>" + " </class>" + " </test>" + " </suite>" + "</testng-results>";
assertXmlEquals(expected, out);
}
use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method testScenarioWithFailedSteps.
@Test
void testScenarioWithFailedSteps() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature\n" + " Scenario: scenario\n" + " When step1\n" + " Then step2\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new TestNGFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("step1", new StubException("message", "stacktrace")), new StubStepDefinition("step2"))).build().run();
String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\">" + " <suite name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"0\">" + " <test name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"0\">" + " <class name=\"feature\">" + " <test-method name=\"scenario\" status=\"FAIL\" duration-ms=\"0\" started-at=\"1970-01-01T00:00:00Z\" finished-at=\"1970-01-01T00:00:00Z\">" + " <exception class=\"io.cucumber.core.plugin.StubException\">" + " <message><![CDATA[When step1..................................................................failed\n" + "Then step2..................................................................skipped\n" + "]]></message>" + " <full-stacktrace><![CDATA[stacktrace]]></full-stacktrace>" + " </exception>" + " </test-method>" + " </class>" + " </test>" + " </suite>" + "</testng-results>";
assertXmlEquals(expected, out);
}
use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments_with_data_table.
@Test
void throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments_with_data_table() {
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");
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 0 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 StepDefinitionMatchTest method throws_could_not_convert_exception_for_transformer_and_capture_group_mismatch.
@Test
void throws_could_not_convert_exception_for_transformer_and_capture_group_mismatch() {
stepTypeRegistry.defineParameterType(new ParameterType<>("itemQuantity", "(few|some|lots of) (cukes|gherkins)", ItemQuantity.class, // Wrong number of capture groups
(String s) -> null));
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some cukes in my belly\n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have {itemQuantity} in my belly", ItemQuantity.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
StepDefinitionMatch 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("Could not convert arguments for step [I have {itemQuantity} in my belly] defined at '{stubbed location with details}'.")));
}
Aggregations