use of io.cucumber.core.backend.StubHookDefinition 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);
}
use of io.cucumber.core.backend.StubHookDefinition in project cucumber-jvm by cucumber.
the class PrettyFormatterTest method should_print_output_from_after_hooks.
@Test
void should_print_output_from_after_hooks() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + " Scenario: scenario name\n" + " Given first step\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(emptyList(), singletonList(new StubStepDefinition("first step", "path/step_definitions.java:3")), singletonList(new StubHookDefinition(testCaseState -> testCaseState.log("printed from hook"))))).build().run();
assertThat(out, bytesContainsString("" + " Given first step # path/step_definitions.java:3\n" + "\n" + " printed from hook\n"));
}
use of io.cucumber.core.backend.StubHookDefinition in project cucumber-jvm by cucumber.
the class PrettyFormatterTest method should_print_error_message_for_before_hooks.
@Test
void should_print_error_message_for_before_hooks() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + " Scenario: scenario name\n" + " Given first step\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition(new StubException())), singletonList(new StubStepDefinition("first step", "path/step_definitions.java:3")), emptyList())).build().run();
assertThat(out, bytesContainsString("" + "Scenario: scenario name # path/test.feature:2\n" + " the stack trace\n" + " Given first step # path/step_definitions.java:3\n"));
}
use of io.cucumber.core.backend.StubHookDefinition in project cucumber-jvm by cucumber.
the class PrettyFormatterTest method should_print_output_from_afterStep_hooks.
@Test
void should_print_output_from_afterStep_hooks() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + " Scenario: scenario name\n" + " Given first step\n" + " When second step\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(emptyList(), emptyList(), asList(new StubStepDefinition("first step", "path/step_definitions.java:3"), new StubStepDefinition("second step", "path/step_definitions.java:4")), singletonList(new StubHookDefinition(testCaseState -> testCaseState.log("printed from afterstep hook"))), emptyList())).build().run();
assertThat(out, bytesContainsString("" + " Given first step # path/step_definitions.java:3\n" + "\n" + " printed from afterstep hook\n" + "\n" + " When second step # path/step_definitions.java:4\n" + "\n" + " printed from afterstep hook" + "\n"));
}
use of io.cucumber.core.backend.StubHookDefinition in project cucumber-jvm by cucumber.
the class PrettyFormatterTest method should_print_error_message_for_after_hooks.
@Test
void should_print_error_message_for_after_hooks() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + " Scenario: scenario name\n" + " Given first step\n");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(emptyList(), singletonList(new StubStepDefinition("first step", "path/step_definitions.java:3")), singletonList(new StubHookDefinition(new StubException())))).build().run();
assertThat(out, bytesContainsString("" + " Given first step # path/step_definitions.java:3\n" + " the stack trace\n"));
}
Aggregations