Search in sources :

Example 1 with CucumberExecutionContext

use of io.cucumber.core.runtime.CucumberExecutionContext 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);
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Description(org.junit.runner.Description) InOrder(org.mockito.InOrder) Feature(io.cucumber.core.gherkin.Feature) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ExitStatus(io.cucumber.core.runtime.ExitStatus) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) Filters(io.cucumber.core.filter.Filters) RunnerSupplier(io.cucumber.core.runtime.RunnerSupplier) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Failure(org.junit.runner.notification.Failure) Test(org.junit.jupiter.api.Test)

Example 2 with CucumberExecutionContext

use of io.cucumber.core.runtime.CucumberExecutionContext 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);
}
Also used : BackendSupplier(io.cucumber.core.runtime.BackendSupplier) ObjectFactoryServiceLoader(io.cucumber.core.runtime.ObjectFactoryServiceLoader) SingletonRunnerSupplier(io.cucumber.core.runtime.SingletonRunnerSupplier) SingletonObjectFactorySupplier(io.cucumber.core.runtime.SingletonObjectFactorySupplier) ThreadLocalObjectFactorySupplier(io.cucumber.core.runtime.ThreadLocalObjectFactorySupplier) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ExitStatus(io.cucumber.core.runtime.ExitStatus) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) SingletonRunnerSupplier(io.cucumber.core.runtime.SingletonRunnerSupplier) RunnerSupplier(io.cucumber.core.runtime.RunnerSupplier) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) BackendServiceLoader(io.cucumber.core.runtime.BackendServiceLoader) PluginFactory(io.cucumber.core.plugin.PluginFactory) SingletonObjectFactorySupplier(io.cucumber.core.runtime.SingletonObjectFactorySupplier) ObjectFactorySupplier(io.cucumber.core.runtime.ObjectFactorySupplier) ThreadLocalObjectFactorySupplier(io.cucumber.core.runtime.ThreadLocalObjectFactorySupplier) Plugins(io.cucumber.core.plugin.Plugins)

Example 3 with CucumberExecutionContext

use of io.cucumber.core.runtime.CucumberExecutionContext 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)"));
}
Also used : RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Feature(io.cucumber.core.gherkin.Feature) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ExitStatus(io.cucumber.core.runtime.ExitStatus) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) Filters(io.cucumber.core.filter.Filters) RunnerSupplier(io.cucumber.core.runtime.RunnerSupplier) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Test(org.junit.jupiter.api.Test)

Example 4 with CucumberExecutionContext

use of io.cucumber.core.runtime.CucumberExecutionContext in project cucumber-jvm by cucumber.

the class FeatureRunnerTest method createFeatureRunner.

private FeatureRunner createFeatureRunner(Feature feature, JUnitOptions junitOption) {
    ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(getClass()::getClassLoader, RuntimeOptions.defaultOptions());
    ObjectFactorySupplier objectFactory = new SingletonObjectFactorySupplier(objectFactoryServiceLoader);
    final RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
    final Clock clockStub = new Clock() {

        @Override
        public ZoneId getZone() {
            return null;
        }

        @Override
        public Clock withZone(ZoneId zone) {
            return null;
        }

        @Override
        public Instant instant() {
            return Instant.EPOCH;
        }
    };
    BackendSupplier backendSupplier = () -> singleton(new StubBackendProviderService.StubBackend());
    EventBus bus = new TimeServiceEventBus(clockStub, UUID::randomUUID);
    Filters filters = new Filters(runtimeOptions);
    ThreadLocalRunnerSupplier runnerSupplier = new ThreadLocalRunnerSupplier(runtimeOptions, bus, backendSupplier, objectFactory);
    CucumberExecutionContext context = new CucumberExecutionContext(bus, new ExitStatus(runtimeOptions), runnerSupplier);
    return FeatureRunner.create(feature, null, filters, context, junitOption);
}
Also used : BackendSupplier(io.cucumber.core.runtime.BackendSupplier) ObjectFactoryServiceLoader(io.cucumber.core.runtime.ObjectFactoryServiceLoader) ZoneId(java.time.ZoneId) SingletonObjectFactorySupplier(io.cucumber.core.runtime.SingletonObjectFactorySupplier) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Clock(java.time.Clock) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) ThreadLocalRunnerSupplier(io.cucumber.core.runtime.ThreadLocalRunnerSupplier) ExitStatus(io.cucumber.core.runtime.ExitStatus) CucumberExecutionContext(io.cucumber.core.runtime.CucumberExecutionContext) Filters(io.cucumber.core.filter.Filters) SingletonObjectFactorySupplier(io.cucumber.core.runtime.SingletonObjectFactorySupplier) ObjectFactorySupplier(io.cucumber.core.runtime.ObjectFactorySupplier) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions)

Aggregations

CucumberExecutionContext (io.cucumber.core.runtime.CucumberExecutionContext)4 ExitStatus (io.cucumber.core.runtime.ExitStatus)4 ThreadLocalRunnerSupplier (io.cucumber.core.runtime.ThreadLocalRunnerSupplier)4 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)4 EventBus (io.cucumber.core.eventbus.EventBus)3 Filters (io.cucumber.core.filter.Filters)3 RuntimeOptions (io.cucumber.core.options.RuntimeOptions)3 RunnerSupplier (io.cucumber.core.runtime.RunnerSupplier)3 UUID (java.util.UUID)3 Feature (io.cucumber.core.gherkin.Feature)2 BackendSupplier (io.cucumber.core.runtime.BackendSupplier)2 ObjectFactoryServiceLoader (io.cucumber.core.runtime.ObjectFactoryServiceLoader)2 ObjectFactorySupplier (io.cucumber.core.runtime.ObjectFactorySupplier)2 SingletonObjectFactorySupplier (io.cucumber.core.runtime.SingletonObjectFactorySupplier)2 Test (org.junit.jupiter.api.Test)2 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)1 PluginFactory (io.cucumber.core.plugin.PluginFactory)1 Plugins (io.cucumber.core.plugin.Plugins)1 BackendServiceLoader (io.cucumber.core.runtime.BackendServiceLoader)1 SingletonRunnerSupplier (io.cucumber.core.runtime.SingletonRunnerSupplier)1