use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method rethrows_target_invocation_exception_for_docstring.
@Test
void rethrows_target_invocation_exception_for_docstring() {
RuntimeException userException = new RuntimeException();
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some cukes in my belly\n" + " \"\"\"doc\n" + " converting this should throw an exception\n" + " \"\"\"\n");
stepTypeRegistry.defineDocStringType(new DocStringType(ItemQuantity.class, "doc", content -> {
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 testScenarioWithFailedBeforeHook.
@Test
void testScenarioWithFailedBeforeHook() {
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(singletonList(new StubHookDefinition(new StubException("message", "stacktrace"))), singletonList(new StubStepDefinition("step")), emptyList())).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...................................................................skipped\n" + "Then step...................................................................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 executes_a_step.
@Test
void executes_a_step() throws Throwable {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have 4 cukes in my belly\n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have {int} cukes in my belly", Integer.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);
stepDefinitionMatch.runStep(null);
}
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_and_no_arguments.
@Test
void throws_arity_mismatch_exception_when_there_are_more_parameters_and_no_arguments() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have cukes in my belly\n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have 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);
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("Step [I have cukes in my belly] is defined with 3 parameters at '{stubbed location with details}'.\n" + "However, the gherkin step has 0 arguments.\n" + "Step text: I have cukes in my belly")));
}
use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_register_type_in_configuration_exception_when_there_is_no_data_table_type_defined.
@Test
void throws_register_type_in_configuration_exception_when_there_is_no_data_table_type_defined() {
Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have a data table\n" + " | A | \n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have a data table", UndefinedDataTableType.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, 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 convert arguments for step [I have a data table] defined at '{stubbed location with details}'.\n" + "It appears you did not register a data table type.")));
}
Aggregations