Search in sources :

Example 76 with TimeServiceEventBus

use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.

the class TeamCityPluginTest method should_handle_scenario_outline.

@Test
void should_handle_scenario_outline() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Scenario Outline: <name>\n" + "    Given first step\n" + "    Then <arg> step\n" + "    Examples: examples name\n" + "      |  name  |  arg   |\n" + "      | name 1 | second |\n" + "      | name 2 | third  |\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new TeamCityPlugin(new PrintStream(out))).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).build().run();
    String location = new File("").toURI().toString();
    String expected = "" + "##teamcity[enteredTheMatrix timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' name = 'Cucumber']\n" + "##teamcity[customProgressStatus testsCategory = 'Scenarios' count = '0' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:1' name = 'feature name']\n" + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:2' name = '<name>']\n" + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:5' name = 'examples name']\n" + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:7' name = 'Example #1']\n" + "##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n" + "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'first step']\n" + "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:4' captureStandardOutput = 'true' name = 'second step']\n" + "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'second step']\n" + "##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #1']\n" + "##teamcity[testSuiteStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:8' name = 'Example #2']\n" + "##teamcity[customProgressStatus type = 'testStarted' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:3' captureStandardOutput = 'true' name = 'first step']\n" + "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'first step']\n" + "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' locationHint = '" + location + "path/test.feature:4' captureStandardOutput = 'true' name = 'third step']\n" + "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' name = 'third step']\n" + "##teamcity[customProgressStatus type = 'testFinished' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Example #2']\n" + "##teamcity[customProgressStatus testsCategory = '' count = '0' timestamp = '1970-01-01T12:00:00.000+0000']\n" + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'examples name']\n" + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = '<name>']\n" + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'feature name']\n" + "##teamcity[testSuiteFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Cucumber']\n";
    assertThat(out, bytesContainsString(expected));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) PrintStream(java.io.PrintStream) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BytesContainsString.bytesContainsString(io.cucumber.core.plugin.BytesContainsString.bytesContainsString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 77 with TimeServiceEventBus

use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method should_format_scenario_outlines_with_multiple_examples.

@Test
void should_format_scenario_outlines_with_multiple_examples() {
    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 1\n" + "    | arg |\n" + "    |  a  |\n" + "    |  b  |\n\n" + "  Examples: examples 2\n" + "    | arg |\n" + "    |  c  |\n" + "    |  d  |\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=\"4\" 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" + "    <testcase classname=\"feature name\" name=\"outline name 3\" time=\"0\">\n" + "        <system-out><![CDATA[" + "Given first step \"c\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "    <testcase classname=\"feature name\" name=\"outline name 4\" time=\"0\">\n" + "        <system-out><![CDATA[" + "Given first step \"d\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\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) 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 78 with TimeServiceEventBus

use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.

the class TimelineFormatterTest method runFormatterWithPlugin.

private void runFormatterWithPlugin() {
    StepDurationTimeService timeService = new StepDurationTimeService(Duration.ofMillis(1000));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(failingFeature, successfulFeature, pendingFeature)).withAdditionalPlugins(timeService).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("bg_1"), new StubStepDefinition("bg_2"), new StubStepDefinition("bg_3"), new StubStepDefinition("step_01"), new StubStepDefinition("step_02"), new StubStepDefinition("step_03", new StubException()), new StubStepDefinition("step_10"), new StubStepDefinition("step_20"), new StubStepDefinition("step_30"))).withRuntimeOptions(runtimeOptionsBuilder.build()).build().run();
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService)

Example 79 with TimeServiceEventBus

use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.

the class TeamCityPluginTest method should_print_system_failure_for_failed_hooks.

@Test
void should_print_system_failure_for_failed_hooks() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    assertThrows(StubException.class, () -> Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new TeamCityPlugin(new PrintStream(out))).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), singletonList(new StubStaticHookDefinition(new StubException("Hook failed", "the stack trace"))))).build().run());
    assertThat(out, bytesContainsString("" + "##teamcity[testStarted timestamp = '1970-01-01T12:00:00.000+0000' name = 'Before All/After All']\n" + "##teamcity[testFailed timestamp = '1970-01-01T12:00:00.000+0000' message = 'Before All/After All failed' details = 'the stack trace' name = 'Before All/After All']\n" + "##teamcity[testFinished timestamp = '1970-01-01T12:00:00.000+0000' name = 'Before All/After All']"));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) PrintStream(java.io.PrintStream) StubStaticHookDefinition(io.cucumber.core.backend.StubStaticHookDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 80 with TimeServiceEventBus

use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.

the class TeamCityPluginTest method should_print_error_message_for_undefined_steps.

@Test
void should_print_error_message_for_undefined_steps() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n" + "    Given second step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new TeamCityPlugin(new PrintStream(out))).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier()).build().run();
    assertThat(out, bytesContainsString("" + "##teamcity[testFailed timestamp = '1970-01-01T12:00:00.000+0000' duration = '0' message = 'Step undefined' details = 'You can implement this step and 1 other step(s) using the snippet(s) below:|n|ntest snippet 0|ntest snippet 1|n' name = 'first step']"));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)80 Test (org.junit.jupiter.api.Test)77 UUID (java.util.UUID)63 ByteArrayOutputStream (java.io.ByteArrayOutputStream)59 Feature (io.cucumber.core.gherkin.Feature)55 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)53 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)52 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)46 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)19 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)19 DocString (io.cucumber.docstring.DocString)17 PluginFactory (io.cucumber.core.plugin.PluginFactory)13 Plugins (io.cucumber.core.plugin.Plugins)13 PrintStream (java.io.PrintStream)12 EventBus (io.cucumber.core.eventbus.EventBus)11 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)6 StubPendingException (io.cucumber.core.backend.StubPendingException)4 TestCaseState (io.cucumber.core.backend.TestCaseState)4 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)4 DataTable (io.cucumber.datatable.DataTable)4