Search in sources :

Example 36 with TimeServiceEventBus

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

the class JUnitFormatterTest method should_handle_pending_in_before_hook.

@Test
void should_handle_pending_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 StubPendingException())), 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 scenario has pending or undefined step(s)\" type=\"io.cucumber.core.backend.StubPendingException\">\n" + "            <![CDATA[Given first step............................................................skipped\n" + "When second step............................................................skipped\n" + "Then third step.............................................................skipped\n" + "]]>\n" + "        </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) 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 37 with TimeServiceEventBus

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

the class JUnitFormatterTest method should_accumulate_time_from_steps_and_hooks.

@Test
void should_accumulate_time_from_steps_and_hooks() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "Feature: feature name\n" + "  Scenario: scenario name\n" + "    * first step\n" + "    * second step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JUnitFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, 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()))).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=\"1\" time=\"0.004\">\n" + "    <testcase classname=\"feature name\" name=\"scenario name\" time=\"0.004\">\n" + "        <system-out><![CDATA[" + "* first step................................................................passed\n" + "* second 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) 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) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 38 with TimeServiceEventBus

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

the class FeatureRunnerTest method should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop.

@Test
void should_notify_of_failure_to_create_runners_and_request_test_execution_to_stop() {
    Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario_1 name\n" + "    Given step #1\n");
    Filters filters = new Filters(RuntimeOptions.defaultOptions());
    IllegalStateException illegalStateException = new IllegalStateException();
    RunnerSupplier runnerSupplier = () -> {
        throw illegalStateException;
    };
    TimeServiceEventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    RuntimeOptions options = RuntimeOptions.defaultOptions();
    CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
    FeatureRunner featureRunner = FeatureRunner.create(feature, null, filters, context, new JUnitOptions());
    RunNotifier notifier = mock(RunNotifier.class);
    PickleRunners.PickleRunner pickleRunner = featureRunner.getChildren().get(0);
    featureRunner.runChild(pickleRunner, notifier);
    Description description = pickleRunner.getDescription();
    ArgumentCaptor<Failure> failureArgumentCaptor = ArgumentCaptor.forClass(Failure.class);
    InOrder order = inOrder(notifier);
    order.verify(notifier).fireTestStarted(description);
    order.verify(notifier).fireTestFailure(failureArgumentCaptor.capture());
    assertThat(failureArgumentCaptor.getValue().getException(), is(equalTo(illegalStateException)));
    assertThat(failureArgumentCaptor.getValue().getDescription(), is(equalTo(description)));
    order.verify(notifier).pleaseStop();
    order.verify(notifier).fireTestFinished(description);
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) Feature(io.cucumber.core.gherkin.Feature) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ExitStatus(io.cucumber.core.runtime.ExitStatus) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) Filters(io.cucumber.core.filter.Filters) RunnerSupplier(io.cucumber.core.runtime.RunnerSupplier) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Failure(org.junit.runner.notification.Failure) Test(org.junit.jupiter.api.Test)

Example 39 with TimeServiceEventBus

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

the class EventBusTest method handlers_receive_the_events_they_registered_for.

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

Example 40 with TimeServiceEventBus

use of io.cucumber.core.runtime.TimeServiceEventBus 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)

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