use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_convert_exception_for_docstring.
@Test
void throws_could_not_convert_exception_for_docstring() {
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 IllegalArgumentException(content);
}));
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);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat(actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have some cukes in my belly] defined at '{stubbed location with details}'.")));
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method testScenarioWithPassedSteps.
@Test
void testScenarioWithPassedSteps() {
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(new StubStepDefinition("step"))).build().run();
String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"1\" failed=\"0\" 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=\"PASS\" duration-ms=\"0\" started-at=\"1970-01-01T00:00:00Z\" finished-at=\"1970-01-01T00:00:00Z\"/>" + " </class>" + " </test>" + " </suite>" + "</testng-results>";
assertXmlEquals(expected, out);
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_invoke_argument_conversion_when_argument_could_not_be_got.
@Test
void throws_could_not_invoke_argument_conversion_when_argument_could_not_be_got() {
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);
List<Argument> arguments = Collections.singletonList(() -> {
throw new CucumberBackendException("This exception is expected", new IllegalAccessException());
});
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 there was a problem with a hook or transformer definition.")));
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_convert_exception_for_singleton_table_dimension_mismatch.
@Test
void throws_could_not_convert_exception_for_singleton_table_dimension_mismatch() {
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");
stepTypeRegistry.defineDataTableType(new DataTableType(ItemQuantity.class, ItemQuantity::new));
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);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat(actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have some cukes in my belly] defined at '{stubbed location with details}'.")));
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method testDurationCalculationOfStepsAndHooks.
@Test
void testDurationCalculationOfStepsAndHooks() {
Feature feature1 = TestFeatureParser.parse("path/feature1.feature", "" + "Feature: feature_1\n" + " Scenario: scenario_1\n" + " When step\n" + " Then step\n" + " Scenario: scenario_2\n" + " When step\n" + " Then step\n");
Feature feature2 = TestFeatureParser.parse("path/feature2.feature", "" + "Feature: feature_2\n" + " Scenario: scenario_3\n" + " When step\n" + " Then step\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
Runtime.builder().withFeatureSupplier(() -> Arrays.asList(feature1, feature2)).withAdditionalPlugins(timeService, new TestNGFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition()), singletonList(new StubStepDefinition("step")), singletonList(new StubHookDefinition()))).build().run();
String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"3\" passed=\"3\" failed=\"0\" skipped=\"0\">" + " <suite name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"12\">" + " <test name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"12\">" + " <class name=\"feature_1\">" + " <test-method name=\"scenario_1\" status=\"PASS\" duration-ms=\"4\" started-at=\"1970-01-01T00:00:00Z\" finished-at=\"1970-01-01T00:00:00.004Z\"/>" + " <test-method name=\"scenario_2\" status=\"PASS\" duration-ms=\"4\" started-at=\"1970-01-01T00:00:00.004Z\" finished-at=\"1970-01-01T00:00:00.008Z\"/>" + " </class>" + " <class name=\"feature_2\">" + " <test-method name=\"scenario_3\" status=\"PASS\" duration-ms=\"4\" started-at=\"1970-01-01T00:00:00.008Z\" finished-at=\"1970-01-01T00:00:00.012Z\"/>" + " </class>" + " </test>" + " </suite>" + "</testng-results>";
assertXmlEquals(expected, out);
}
Aggregations