use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class JUnitFormatterTest method should_format_background.
@Test
void should_format_background() {
Feature feature = TestFeatureParser.parse("path/test.feature", "Feature: feature name\n" + " Background:\n" + " Given first background step\n" + " When second background step\n" + " Then third background step\n" + " Scenario: scenario name\n" + " Given first step\n" + " When second step\n" + " Then third step\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new JUnitFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first background step"), new StubStepDefinition("second background step"), new StubStepDefinition("third background step"), new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).build().run();
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite errors=\"0\" failures=\"0\" name=\"io.cucumber.core.plugin.JUnitFormatter\" skipped=\"0\" tests=\"1\" time=\"0\">\n" + " <testcase classname=\"feature name\" name=\"scenario name\" time=\"0\">\n" + " <system-out>\n" + " <![CDATA[Given first background step.................................................passed\n" + "When second background step.................................................passed\n" + "Then third background step..................................................passed\n" + "Given first step............................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]>\n" + " </system-out>\n" + " </testcase>\n" + "</testsuite>\n";
assertXmlEqual(expected, out);
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class JUnitFormatterTest method should_format_skipped_scenario.
@Test
void should_format_skipped_scenario() {
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");
RuntimeException exception = new TestAbortedException("message");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new JUnitFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", exception), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).build().run();
String stackTrace = getStackTrace(exception);
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"0\" name=\"io.cucumber.core.plugin.JUnitFormatter\" skipped=\"1\" errors=\"0\" tests=\"1\" time=\"0\">\n" + " <testcase classname=\"feature name\" name=\"scenario name\" time=\"0\">\n" + " <skipped message=\"" + stackTrace.replace("\n\t", " 	").replaceAll("\r", " ") + "\"><![CDATA[" + "Given first step............................................................skipped\n" + "When second step............................................................skipped\n" + "Then third step.............................................................skipped\n" + "\n" + "StackTrace:\n" + stackTrace + "]]></skipped>\n" + " </testcase>\n" + "</testsuite>\n";
assertXmlEqual(expected, out);
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class JUnitFormatterTest method should_format_scenario_outlines.
@Test
void should_format_scenario_outlines() {
Feature feature = TestFeatureParser.parse("path/test.feature", "Feature: feature name\n" + " Scenario Outline: outline_name\n" + " Given first step \"<arg>\"\n" + " When second step\n" + " Then third step\n\n" + " Examples: examples\n" + " | arg |\n" + " | a |\n" + " | b |\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new JUnitFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step {string}", String.class), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).build().run();
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"0\" name=\"io.cucumber.core.plugin.JUnitFormatter\" skipped=\"0\" errors=\"0\" tests=\"2\" time=\"0\">\n" + " <testcase classname=\"feature name\" name=\"outline_name\" time=\"0\">\n" + " <system-out><![CDATA[" + "Given first step \"a\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + " </testcase>\n" + " <testcase classname=\"feature name\" name=\"outline_name_2\" time=\"0\">\n" + " <system-out><![CDATA[" + "Given first step \"b\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + " </testcase>\n" + "</testsuite>\n";
assertXmlEqual(expected, out);
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class RerunFormatterTest method should_one_entry_for_each_failing_feature.
@Test
void should_one_entry_for_each_failing_feature() {
Feature feature1 = TestFeatureParser.parse("classpath:path/first.feature", "" + "Feature: feature 1 name\n" + " Scenario: scenario 1 name\n" + " When first step\n" + " Then second step\n");
Feature feature2 = TestFeatureParser.parse("classpath:path/second.feature", "" + "Feature: feature 2 name\n" + " Scenario: scenario 2 name\n" + " When third step\n" + " Then forth step\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2)).withAdditionalPlugins(new RerunFormatter(out)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step"), new StubStepDefinition("second step", new StubException()), new StubStepDefinition("third step", new StubException()), new StubStepDefinition("forth step"))).build().run();
assertThat(out, isBytesEqualTo("classpath:path/first.feature:2\nclasspath:path/second.feature:2\n"));
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class JsonFormatterTest method should_add_step_hooks_to_step.
@Test
void should_add_step_hooks_to_step() {
Feature feature = TestFeatureParser.parse("file:path/test.feature", "" + "Feature: Banana party\n" + "\n" + " Scenario: Monkey eats bananas\n" + " Given there are bananas\n" + " When monkey arrives\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(emptyList(), singletonList(new StubHookDefinition("Hooks.beforestep_hooks_1()")), asList(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()"), new StubStepDefinition("monkey arrives", "StepDefs.monkey_arrives()")), asList(new StubHookDefinition("Hooks.afterstep_hooks_1()"), new StubHookDefinition("Hooks.afterstep_hooks_2()")), emptyList())).build().run();
String expected = "" + "[\n" + " {\n" + " \"line\": 1,\n" + " \"elements\": [\n" + " {\n" + " \"line\": 3,\n" + " \"name\": \"Monkey eats bananas\",\n" + " \"description\": \"\",\n" + " \"id\": \"banana-party;monkey-eats-bananas\",\n" + " \"type\": \"scenario\",\n" + " \"keyword\": \"Scenario\",\n" + " \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + " \"steps\": [\n" + " {\n" + " \"result\": {\n" + " \"duration\": 1000000,\n" + " \"status\": \"passed\"\n" + " },\n" + " \"before\": [\n" + " {\n" + " \"result\": {\n" + " \"duration\": 1000000,\n" + " \"status\": \"passed\"\n" + " },\n" + " \"match\": {\n" + " \"location\": \"Hooks.beforestep_hooks_1()\"\n" + " }\n" + " }\n" + " ],\n" + " \"line\": 4,\n" + " \"name\": \"there are bananas\",\n" + " \"match\": {\n" + " \"location\": \"StepDefs.there_are_bananas()\"\n" + " },\n" + " \"after\": [\n" + " {\n" + " \"result\": {\n" + " \"duration\": 1000000,\n" + " \"status\": \"passed\"\n" + " },\n" + " \"match\": {\n" + " \"location\": \"Hooks.afterstep_hooks_2()\"\n" + " }\n" + " },\n" + " {\n" + " \"result\": {\n" + " \"duration\": 1000000,\n" + " \"status\": \"passed\"\n" + " },\n" + " \"match\": {\n" + " \"location\": \"Hooks.afterstep_hooks_1()\"\n" + " }\n" + " }\n" + " ],\n" + " \"keyword\": \"Given \"\n" + " },\n" + " {\n" + " \"result\": {\n" + " \"duration\": 1000000,\n" + " \"status\": \"passed\"\n" + " },\n" + " \"before\": [\n" + " {\n" + " \"result\": {\n" + " \"duration\": 1000000,\n" + " \"status\": \"passed\"\n" + " },\n" + " \"match\": {\n" + " \"location\": \"Hooks.beforestep_hooks_1()\"\n" + " }\n" + " }\n" + " ],\n" + " \"line\": 5,\n" + " \"name\": \"monkey arrives\",\n" + " \"match\": {\n" + " \"location\": \"StepDefs.monkey_arrives()\"\n" + " },\n" + " \"after\": [\n" + " {\n" + " \"result\": {\n" + " \"duration\": 1000000,\n" + " \"status\": \"passed\"\n" + " },\n" + " \"match\": {\n" + " \"location\": \"Hooks.afterstep_hooks_2()\"\n" + " }\n" + " },\n" + " {\n" + " \"result\": {\n" + " \"duration\": 1000000,\n" + " \"status\": \"passed\"\n" + " },\n" + " \"match\": {\n" + " \"location\": \"Hooks.afterstep_hooks_1()\"\n" + " }\n" + " }\n" + " ],\n" + " \"keyword\": \"When \"\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + " \"name\": \"Banana party\",\n" + " \"description\": \"\",\n" + " \"id\": \"banana-party\",\n" + " \"keyword\": \"Feature\",\n" + " \"uri\": \"file:path/test.feature\",\n" + " \"tags\": []\n" + " }\n" + "]";
assertJsonEquals(expected, out);
}
Aggregations