Search in sources :

Example 16 with StubHookDefinition

use of io.cucumber.core.backend.StubHookDefinition 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);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 17 with StubHookDefinition

use of io.cucumber.core.backend.StubHookDefinition 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);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 18 with StubHookDefinition

use of io.cucumber.core.backend.StubHookDefinition in project cucumber-jvm by cucumber.

the class PrettyFormatterTest method should_print_output_from_before_hooks.

@Test
void should_print_output_from_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(testCaseState -> testCaseState.log("printed from hook"))), singletonList(new StubStepDefinition("first step", "path/step_definitions.java:3")), emptyList())).build().run();
    assertThat(out, bytesContainsString("" + "Scenario: scenario name # path/test.feature:2\n" + "\n" + "    printed from hook\n" + "\n" + "  Given first step      # path/step_definitions.java:3\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Runtime(io.cucumber.core.runtime.Runtime) Formats.ansi(io.cucumber.core.plugin.Formats.ansi) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Collections.singletonList(java.util.Collections.singletonList) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStaticHookDefinition(io.cucumber.core.backend.StubStaticHookDefinition) StepExpression(io.cucumber.core.stepexpression.StepExpression) Locale(java.util.Locale) Arrays.asList(java.util.Arrays.asList) BytesContainsString.bytesContainsString(io.cucumber.core.plugin.BytesContainsString.bytesContainsString) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataTable(io.cucumber.datatable.DataTable) BytesEqualTo.isBytesEqualTo(io.cucumber.core.plugin.BytesEqualTo.isBytesEqualTo) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) EventBus(io.cucumber.core.eventbus.EventBus) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StepTypeRegistry(io.cucumber.core.stepexpression.StepTypeRegistry) Collections.emptyList(java.util.Collections.emptyList) StepExpressionFactory(io.cucumber.core.stepexpression.StepExpressionFactory) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) TestDefinitionArgument.createArguments(io.cucumber.core.runner.TestDefinitionArgument.createArguments) Test(org.junit.jupiter.api.Test) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Feature(io.cucumber.core.gherkin.Feature) Clock(java.time.Clock) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 19 with StubHookDefinition

use of io.cucumber.core.backend.StubHookDefinition in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_handle_failure_in_before_hook.

@Test
void should_handle_failure_in_before_hook() {
    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");
    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(singletonList(new StubHookDefinition(new StubException("the message", "the stack trace"))), Arrays.asList(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step")), singletonList(new StubHookDefinition()))).build().run();
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"1\" name=\"io.cucumber.core.plugin.JUnitFormatter\" skipped=\"0\" errors=\"0\" tests=\"1\" time=\"0\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0\">\n" + "        <failure message=\"the message\" type=\"io.cucumber.core.plugin.StubException\"><![CDATA[" + "Given first step............................................................skipped\n" + "When second step............................................................skipped\n" + "Then third step.............................................................skipped\n" + "\n" + "StackTrace:\n" + "the stack trace" + "]]></failure>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 20 with StubHookDefinition

use of io.cucumber.core.backend.StubHookDefinition in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_handle_failure_in_after_hook.

@Test
void should_handle_failure_in_after_hook() {
    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");
    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(singletonList(new StubHookDefinition()), Arrays.asList(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step")), singletonList(new StubHookDefinition(new StubException("the message", "the stack trace"))))).build().run();
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"1\" name=\"io.cucumber.core.plugin.JUnitFormatter\" skipped=\"0\" errors=\"0\" tests=\"1\" time=\"0\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0\">\n" + "        <failure message=\"the message\" type=\"io.cucumber.core.plugin.StubException\"><![CDATA[" + "Given first step............................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "\n" + "StackTrace:\n" + "the stack trace" + "]]></failure>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)26 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)26 Feature (io.cucumber.core.gherkin.Feature)26 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)26 ByteArrayOutputStream (java.io.ByteArrayOutputStream)26 Test (org.junit.jupiter.api.Test)26 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)25 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)22 UUID (java.util.UUID)22 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)8 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)7 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)6 Runtime (io.cucumber.core.runtime.Runtime)6 DataTable (io.cucumber.datatable.DataTable)6 PrintStream (java.io.PrintStream)6 Arrays.asList (java.util.Arrays.asList)6 Collections.emptyList (java.util.Collections.emptyList)6 Collections.singletonList (java.util.Collections.singletonList)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 DocString (io.cucumber.docstring.DocString)5