use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method testScenarioWithFailedAfterHook.
@Test
void testScenarioWithFailedAfterHook() {
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(emptyList(), singletonList(new StubStepDefinition("step")), singletonList(new StubHookDefinition(new StubException("message", "stacktrace"))))).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...................................................................passed\n" + "Then step...................................................................passed\n" + "]]></message>" + " <full-stacktrace><![CDATA[stacktrace]]></full-stacktrace>" + " </exception>" + " </test-method>" + " </class>" + " </test>" + " </suite>" + "</testng-results>";
assertXmlEquals(expected, out);
}
use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class TestNGFormatterTest method testScenarioWithFailedSteps.
@Test
void testScenarioWithFailedSteps() {
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 StubException("message", "stacktrace")), new StubStepDefinition("step2"))).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 step1..................................................................failed\n" + "Then step2..................................................................skipped\n" + "]]></message>" + " <full-stacktrace><![CDATA[stacktrace]]></full-stacktrace>" + " </exception>" + " </test-method>" + " </class>" + " </test>" + " </suite>" + "</testng-results>";
assertXmlEquals(expected, out);
}
use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class JUnitReporterWithStepNotificationsTest method ignores_steps_when_step_notification_are_disabled.
@Test
void ignores_steps_when_step_notification_are_disabled() {
EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
JUnitReporter jUnitReporter = new JUnitReporter(bus, new JUnitOptionsBuilder().setStepNotifications(false).build());
jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
bus.send(new TestCaseStarted(now(), testCase));
bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
Result result = new Result(Status.PASSED, ZERO, null);
bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
bus.send(new TestCaseFinished(now(), testCase, result));
verify(runNotifier, never()).fireTestStarted(pickleRunner.describeChild(step));
verify(runNotifier, never()).fireTestFinished(pickleRunner.describeChild(step));
}
use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class CucumberEngineExecutionContext method createCucumberExecutionContext.
private CucumberExecutionContext createCucumberExecutionContext() {
Supplier<ClassLoader> classLoader = CucumberEngineExecutionContext.class::getClassLoader;
ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(classLoader, options);
EventBus bus = synchronize(new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID));
Plugins plugins = new Plugins(new PluginFactory(), options);
ExitStatus exitStatus = new ExitStatus(options);
plugins.addPlugin(exitStatus);
RunnerSupplier runnerSupplier;
if (options.isParallelExecutionEnabled()) {
plugins.setSerialEventBusOnEventListenerPlugins(bus);
ObjectFactorySupplier objectFactorySupplier = new ThreadLocalObjectFactorySupplier(objectFactoryServiceLoader);
BackendSupplier backendSupplier = new BackendServiceLoader(classLoader, objectFactorySupplier);
runnerSupplier = new ThreadLocalRunnerSupplier(options, bus, backendSupplier, objectFactorySupplier);
} else {
plugins.setEventBusOnEventListenerPlugins(bus);
ObjectFactorySupplier objectFactorySupplier = new SingletonObjectFactorySupplier(objectFactoryServiceLoader);
BackendSupplier backendSupplier = new BackendServiceLoader(classLoader, objectFactorySupplier);
runnerSupplier = new SingletonRunnerSupplier(options, bus, backendSupplier, objectFactorySupplier);
}
return new CucumberExecutionContext(bus, exitStatus, runnerSupplier);
}
use of io.cucumber.core.runtime.TimeServiceEventBus in project cucumber-jvm by cucumber.
the class FeatureRunnerTest method should_filter_pickles.
@Test
void should_filter_pickles() {
Feature feature = TestPickleBuilder.parseFeature("path/test.feature", "" + "Feature: feature name\n" + " Scenario: scenario_1 name\n" + " Given step #1\n" + " @tag\n" + " Scenario: scenario_2 name\n" + " Given step #1\n");
RuntimeOptions options = new RuntimeOptionsBuilder().addTagFilter(TagExpressionParser.parse("@tag")).build();
Filters filters = new Filters(options);
IllegalStateException illegalStateException = new IllegalStateException();
RunnerSupplier runnerSupplier = () -> {
throw illegalStateException;
};
EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(options), runnerSupplier);
FeatureRunner featureRunner = FeatureRunner.create(feature, null, filters, context, new JUnitOptions());
assertThat(featureRunner.getChildren().size(), is(1));
assertThat(featureRunner.getChildren().get(0).getDescription().getDisplayName(), is("scenario_2 name(feature name)"));
}
Aggregations