Search in sources :

Example 1 with TestRunFinished

use of io.cucumber.plugin.event.TestRunFinished 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 TestRunFinished

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

the class CucumberExecutionContextTest method emits_failures_in_events.

@Test
public void emits_failures_in_events() {
    List<TestRunStarted> testRunStarted = new ArrayList<>();
    List<TestRunFinished> testRunFinished = new ArrayList<>();
    bus.registerHandlerFor(TestRunStarted.class, testRunStarted::add);
    bus.registerHandlerFor(TestRunFinished.class, testRunFinished::add);
    context.startTestRun();
    assertThrows(IllegalStateException.class, () -> context.runTestCase(runner -> {
        throw failure;
    }));
    context.finishTestRun();
    assertThat(testRunStarted.get(0), notNullValue());
    Result result = testRunFinished.get(0).getResult();
    assertThat(result.getStatus(), is(Status.FAILED));
    assertThat(result.getError(), is(failure));
}
Also used : TestRunStarted(io.cucumber.plugin.event.TestRunStarted) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Result(io.cucumber.plugin.event.Result) TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Status(io.cucumber.plugin.event.Status) UUID(java.util.UUID) TestCase(io.cucumber.plugin.event.TestCase) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) List(java.util.List) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) Duration(java.time.Duration) Clock(java.time.Clock) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) EventBus(io.cucumber.core.eventbus.EventBus) Mockito.mock(org.mockito.Mockito.mock) ArrayList(java.util.ArrayList) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 3 with TestRunFinished

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

the class CucumberExecutionContext method emitTestRunFinished.

private void emitTestRunFinished(Throwable exception) {
    Instant instant = bus.getInstant();
    Result result = new Result(exception != null ? Status.FAILED : exitStatus.getStatus(), Duration.between(start, instant), exception);
    bus.send(new TestRunFinished(instant, result));
    io.cucumber.messages.types.TestRunFinished testRunFinished = new io.cucumber.messages.types.TestRunFinished(exception != null ? printStackTrace(exception) : null, exception == null && exitStatus.isSuccess(), javaInstantToTimestamp(instant));
    Envelope envelope = new Envelope();
    envelope.setTestRunFinished(testRunFinished);
    bus.send(envelope);
}
Also used : Instant(java.time.Instant) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Envelope(io.cucumber.messages.types.Envelope) Result(io.cucumber.plugin.event.Result)

Example 4 with TestRunFinished

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

the class DefaultSummaryPrinterTest method does_not_print_duplicate_snippets.

@Test
void does_not_print_duplicate_snippets() {
    bus.send(new SnippetsSuggestedEvent(bus.getInstant(), URI.create("classpath:com/example.feature"), new Location(12, -1), new Location(13, -1), new Suggestion("", singletonList("snippet"))));
    bus.send(new SnippetsSuggestedEvent(bus.getInstant(), URI.create("classpath:com/example.feature"), new Location(12, -1), new Location(14, -1), new Suggestion("", singletonList("snippet"))));
    bus.send(new TestRunFinished(bus.getInstant(), new Result(Status.PASSED, Duration.ZERO, null)));
    assertThat(new String(out.toByteArray(), UTF_8), equalToCompressingWhiteSpace("" + "\n" + "0 Scenarios\n" + "0 Steps\n" + "0m0.000s\n" + "\n" + "\n" + "You can implement missing steps with the snippets below:\n" + "\n" + "snippet\n" + "\n" + "\n"));
}
Also used : Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) SnippetsSuggestedEvent(io.cucumber.plugin.event.SnippetsSuggestedEvent) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Location(io.cucumber.plugin.event.Location) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Aggregations

Result (io.cucumber.plugin.event.Result)4 TestRunFinished (io.cucumber.plugin.event.TestRunFinished)4 Test (org.junit.jupiter.api.Test)3 UUID (java.util.UUID)2 EventBus (io.cucumber.core.eventbus.EventBus)1 RuntimeOptions (io.cucumber.core.options.RuntimeOptions)1 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)1 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)1 Envelope (io.cucumber.messages.types.Envelope)1 Location (io.cucumber.plugin.event.Location)1 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)1 Suggestion (io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion)1 Status (io.cucumber.plugin.event.Status)1 StepDefinedEvent (io.cucumber.plugin.event.StepDefinedEvent)1 TestCase (io.cucumber.plugin.event.TestCase)1 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)1 TestRunStarted (io.cucumber.plugin.event.TestRunStarted)1 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Clock (java.time.Clock)1