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