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