Search in sources :

Example 6 with TimeServiceEventBus

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

the class TestNGFormatterTest method testScenarioWithPendingSteps.

@Test
void testScenarioWithPendingSteps() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step1\n" + "    Then step2\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("step1", new StubPendingException()), new StubStepDefinition("step2"))).build().run();
    String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testng-results failed=\"1\" passed=\"0\" skipped=\"0\" total=\"1\">\n" + "    <suite duration-ms=\"0\" name=\"io.cucumber.core.plugin.TestNGFormatter\">\n" + "        <test duration-ms=\"0\" name=\"io.cucumber.core.plugin.TestNGFormatter\">\n" + "            <class name=\"feature\">\n" + "                <test-method duration-ms=\"0\" finished-at=\"1970-01-01T00:00:00Z\" name=\"scenario\" started-at=\"1970-01-01T00:00:00Z\" status=\"FAIL\">\n" + "                    <exception class=\"The scenario has pending or undefined step(s)\">\n" + "                        <message>\n" + "                            <![CDATA[When step1..................................................................pending\n" + "Then step2..................................................................skipped\n" + "]]>\n" + "                        </message>\n" + "                        <full-stacktrace>\n" + "                            <![CDATA[The scenario has pending or undefined step(s)]]>\n" + "                        </full-stacktrace>\n" + "                    </exception>\n" + "                </test-method>\n" + "            </class>\n" + "        </test>\n" + "    </suite>\n" + "</testng-results>\n";
    assertXmlEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubPendingException(io.cucumber.core.backend.StubPendingException) 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 7 with TimeServiceEventBus

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

the class UnusedStepsSummaryPrinterTest method verifyUnusedStepsPrinted.

@Test
void verifyUnusedStepsPrinted() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    UnusedStepsSummaryPrinter summaryPrinter = new UnusedStepsSummaryPrinter(out);
    summaryPrinter.setMonochrome(true);
    TimeServiceEventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    summaryPrinter.setEventPublisher(bus);
    // Register two steps, use one, then finish the test run
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/belly.feature:3", "a few cukes")));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/tummy.feature:5", "some more cukes")));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/gut.feature:7", "even more cukes")));
    bus.send(new TestStepFinished(bus.getInstant(), mock(TestCase.class), mockTestStep("my/belly.feature:3"), new Result(Status.UNUSED, Duration.ZERO, null)));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/belly.feature:3", "a few cukes")));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/tummy.feature:5", "some more cukes")));
    bus.send(new StepDefinedEvent(bus.getInstant(), mockStepDef("my/gut.feature:7", "even more cukes")));
    bus.send(new TestStepFinished(bus.getInstant(), mock(TestCase.class), mockTestStep("my/gut.feature:7"), new Result(Status.UNUSED, Duration.ZERO, null)));
    bus.send(new TestRunFinished(bus.getInstant(), new Result(Status.PASSED, Duration.ZERO, null)));
    // Verify produced output
    assertThat(out, isBytesEqualTo("1 Unused steps:\n" + "my/tummy.feature:5 # some more cukes\n"));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StepDefinedEvent(io.cucumber.plugin.event.StepDefinedEvent) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 8 with TimeServiceEventBus

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

the class EventBusTest method handlers_do_not_receive_the_events_they_did_not_registered_for.

@Test
void handlers_do_not_receive_the_events_they_did_not_registered_for() {
    EventHandler handler = mock(EventHandler.class);
    PickleStepTestStep testStep = mock(PickleStepTestStep.class);
    TestCase testCase = mock(TestCase.class);
    TestStepStarted event = new TestStepStarted(EPOCH, testCase, testStep);
    EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
    bus.registerHandlerFor(TestStepFinished.class, handler);
    bus.send(event);
    verify(handler, never()).receive(event);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestCase(io.cucumber.plugin.event.TestCase) EventHandler(io.cucumber.plugin.event.EventHandler) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) Test(org.junit.jupiter.api.Test)

Example 9 with TimeServiceEventBus

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

the class PluginFactoryTest method plugin_does_not_buffer_its_output.

@Test
void plugin_does_not_buffer_its_output() {
    PrintStream previousSystemOut = System.out;
    OutputStream mockSystemOut = new ByteArrayOutputStream();
    try {
        System.setOut(new PrintStream(mockSystemOut));
        // Need to create a new plugin factory here since we need it to pick
        // up the new value of System.out
        fc = new PluginFactory();
        PluginOption option = parse("progress");
        ProgressFormatter plugin = (ProgressFormatter) fc.create(option);
        EventBus bus = new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID);
        plugin.setEventPublisher(bus);
        Result result = new Result(Status.PASSED, ZERO, null);
        TestStepFinished event = new TestStepFinished(bus.getInstant(), mock(TestCase.class), mock(PickleStepTestStep.class), result);
        bus.send(event);
        assertThat(mockSystemOut.toString(), is(not(equalTo(""))));
    } finally {
        System.setOut(previousSystemOut);
    }
}
Also used : PrintStream(java.io.PrintStream) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ClockStub(io.cucumber.core.runner.ClockStub) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Result(io.cucumber.plugin.event.Result) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) PluginOption(io.cucumber.core.options.PluginOption) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 10 with TimeServiceEventBus

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

the class HtmlFormatterTest method ignores_step_definitions.

@Test
void ignores_step_definitions() throws Throwable {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    HtmlFormatter formatter = new HtmlFormatter(bytes);
    EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    formatter.setEventPublisher(bus);
    TestRunStarted testRunStarted = new TestRunStarted();
    testRunStarted.setTimestamp(new Timestamp(10L, 0L));
    Envelope testRunStartedEnvelope = new Envelope();
    testRunStartedEnvelope.setTestRunStarted(testRunStarted);
    bus.send(testRunStartedEnvelope);
    StepDefinition stepDefinition = new StepDefinition();
    Envelope stepDefinitionEnvelope = new Envelope();
    stepDefinitionEnvelope.setStepDefinition(stepDefinition);
    bus.send(stepDefinitionEnvelope);
    Hook hook = new Hook();
    Envelope hookEnvelope = new Envelope();
    hookEnvelope.setHook(hook);
    bus.send(hookEnvelope);
    ParameterType parameterType = new ParameterType();
    Envelope parameterTypeEnvelope = new Envelope();
    parameterTypeEnvelope.setParameterType(parameterType);
    bus.send(parameterTypeEnvelope);
    TestRunFinished testRunFinished = new TestRunFinished();
    testRunFinished.setTimestamp(new Timestamp(15L, 0L));
    Envelope testRunFinishedEnvelope = new Envelope();
    testRunFinishedEnvelope.setTestRunFinished(testRunFinished);
    bus.send(testRunFinishedEnvelope);
    String html = new String(bytes.toByteArray(), UTF_8);
    assertThat(html, containsString("" + "window.CUCUMBER_MESSAGES = [" + "{\"testRunStarted\":{\"timestamp\":{\"seconds\":10,\"nanos\":0}}}," + "{\"testRunFinished\":{\"timestamp\":{\"seconds\":15,\"nanos\":0}}}" + "];\n"));
}
Also used : Hook(io.cucumber.messages.types.Hook) ParameterType(io.cucumber.messages.types.ParameterType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Envelope(io.cucumber.messages.types.Envelope) TestRunFinished(io.cucumber.messages.types.TestRunFinished) Timestamp(io.cucumber.messages.types.Timestamp) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestRunStarted(io.cucumber.messages.types.TestRunStarted) StepDefinition(io.cucumber.messages.types.StepDefinition) UUID(java.util.UUID) 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