Search in sources :

Example 1 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished 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 2 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished in project cucumber-jvm by cucumber.

the class RuntimeTest method should_fail_on_event_listener_exception_when_running_in_parallel.

@Test
void should_fail_on_event_listener_exception_when_running_in_parallel() {
    Feature feature1 = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name 1\n" + "  Scenario: scenario_1 name\n" + "    Given first step\n" + "  Scenario: scenario_2 name\n" + "    Given first step\n");
    Feature feature2 = TestFeatureParser.parse("path/test2.feature", "" + "Feature: feature name 2\n" + "  Scenario: scenario_2 name\n" + "    Given first step\n");
    ConcurrentEventListener brokenEventListener = publisher -> publisher.registerHandlerFor(TestStepFinished.class, (TestStepFinished event) -> {
        throw new RuntimeException("This exception is expected");
    });
    Executable testMethod = () -> Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2)).withAdditionalPlugins(brokenEventListener).withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(2).build()).build().run();
    CompositeCucumberException actualThrown = assertThrows(CompositeCucumberException.class, testMethod);
    assertThat(actualThrown.getMessage(), is(equalTo("There were 3 exceptions. The details are in the stacktrace below.")));
    assertThat(actualThrown.getSuppressed(), is(arrayWithSize(3)));
}
Also used : ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Meta(io.cucumber.messages.types.Meta) Status(io.cucumber.plugin.event.Status) ScenarioScoped(io.cucumber.core.backend.ScenarioScoped) Collections.singletonList(java.util.Collections.singletonList) StepDefinedEvent(io.cucumber.plugin.event.StepDefinedEvent) Arrays.asList(java.util.Arrays.asList) CompositeCucumberException(io.cucumber.core.exception.CompositeCucumberException) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) TestBackendSupplier(io.cucumber.core.runner.TestBackendSupplier) HookDefinition(io.cucumber.core.backend.HookDefinition) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Envelope(io.cucumber.messages.types.Envelope) Result(io.cucumber.plugin.event.Result) Collections.emptyList(java.util.Collections.emptyList) Glue(io.cucumber.core.backend.Glue) UUID(java.util.UUID) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Matchers.matchesPattern(org.hamcrest.Matchers.matchesPattern) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) ZERO(java.time.Duration.ZERO) Mockito.mock(org.mockito.Mockito.mock) Plugin(io.cucumber.plugin.Plugin) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) StepDefinition(io.cucumber.plugin.event.StepDefinition) ZoneId.of(java.time.ZoneId.of) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) EventListener(io.cucumber.plugin.EventListener) ArrayList(java.util.ArrayList) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) ArgumentCaptor(org.mockito.ArgumentCaptor) ParameterInfo(io.cucumber.core.backend.ParameterInfo) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestCaseState(io.cucumber.core.backend.TestCaseState) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) EventPublisher(io.cucumber.plugin.event.EventPublisher) EventBus(io.cucumber.core.eventbus.EventBus) Clock.fixed(java.time.Clock.fixed) TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Clock(java.time.Clock) HOURS(java.util.concurrent.TimeUnit.HOURS) EPOCH(java.time.Instant.EPOCH) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) CompositeCucumberException(io.cucumber.core.exception.CompositeCucumberException) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) Test(org.junit.jupiter.api.Test)

Example 3 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished in project cucumber-jvm by cucumber.

the class PickleStepTestStepTest method step_execution_time_is_measured.

@Test
void step_execution_time_is_measured() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n");
    TestStep step = new PickleStepTestStep(UUID.randomUUID(), URI.create("file:path/to.feature"), feature.getPickles().get(0).getSteps().get(0), definitionMatch);
    when(bus.getInstant()).thenReturn(ofEpochMilli(234L), ofEpochMilli(1234L));
    step.run(testCase, bus, state, ExecutionMode.RUN);
    ArgumentCaptor<TestCaseEvent> captor = forClass(TestCaseEvent.class);
    verify(bus, times(4)).send(captor.capture());
    List<TestCaseEvent> allValues = captor.getAllValues();
    TestStepStarted started = (TestStepStarted) allValues.get(0);
    TestStepFinished finished = (TestStepFinished) allValues.get(2);
    assertAll(() -> assertThat(started.getInstant(), is(equalTo(ofEpochMilli(234L)))), () -> assertThat(finished.getInstant(), is(equalTo(ofEpochMilli(1234L)))), () -> assertThat(finished.getResult().getDuration(), is(equalTo(ofMillis(1000L)))));
}
Also used : TestCaseEvent(io.cucumber.plugin.event.TestCaseEvent) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) Feature(io.cucumber.core.gherkin.Feature) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) Test(org.junit.jupiter.api.Test)

Example 4 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished 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 5 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished in project cucumber-jvm by cucumber.

the class UsageFormatterTest method resultWithPassedAndFailedStep.

@Test
void resultWithPassedAndFailedStep() {
    OutputStream out = new ByteArrayOutputStream();
    UsageFormatter usageFormatter = new UsageFormatter(out);
    TestStep testStep = mockTestStep();
    Result passed = new Result(Status.PASSED, Duration.ofSeconds(12345L), null);
    usageFormatter.handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, passed));
    Result failed = new Result(Status.FAILED, Duration.ZERO, null);
    usageFormatter.handleTestStepFinished(new TestStepFinished(Instant.EPOCH, mock(TestCase.class), testStep, failed));
    Map<String, List<UsageFormatter.StepContainer>> usageMap = usageFormatter.usageMap;
    assertThat(usageMap.size(), is(equalTo(1)));
    List<UsageFormatter.StepContainer> durationEntries = usageMap.get("stepDef");
    assertThat(durationEntries.size(), is(equalTo(1)));
    assertThat(durationEntries.get(0).getName(), is(equalTo("step")));
    assertThat(durationEntries.get(0).getDurations().size(), is(equalTo(1)));
    assertThat(durationEntries.get(0).getDurations().get(0).getDuration(), is(closeTo(12345.0, EPSILON)));
}
Also used : TestStep(io.cucumber.plugin.event.TestStep) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Aggregations

TestStepFinished (io.cucumber.plugin.event.TestStepFinished)33 Result (io.cucumber.plugin.event.Result)31 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)24 Test (org.junit.jupiter.api.Test)24 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)17 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)16 Test (org.testng.annotations.Test)8 Failure (org.junit.runner.notification.Failure)7 SkipException (org.testng.SkipException)7 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)6 Arrays.asList (java.util.Arrays.asList)6 Collections.singletonList (java.util.Collections.singletonList)6 List (java.util.List)6 UUID (java.util.UUID)6 EventBus (io.cucumber.core.eventbus.EventBus)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 CucumberException (io.cucumber.core.exception.CucumberException)4 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)4 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)4 TestCase (io.cucumber.plugin.event.TestCase)4