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"));
}
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));
}
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);
}
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"));
}
Aggregations