Search in sources :

Example 1 with RunnerSupplier

use of io.cucumber.core.runtime.RunnerSupplier 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 RunnerSupplier

use of io.cucumber.core.runtime.RunnerSupplier 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 RunnerSupplier

use of io.cucumber.core.runtime.RunnerSupplier 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)

Aggregations

CucumberExecutionContext (io.cucumber.core.runtime.CucumberExecutionContext)3 ExitStatus (io.cucumber.core.runtime.ExitStatus)3 RunnerSupplier (io.cucumber.core.runtime.RunnerSupplier)3 ThreadLocalRunnerSupplier (io.cucumber.core.runtime.ThreadLocalRunnerSupplier)3 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)3 EventBus (io.cucumber.core.eventbus.EventBus)2 Filters (io.cucumber.core.filter.Filters)2 Feature (io.cucumber.core.gherkin.Feature)2 RuntimeOptions (io.cucumber.core.options.RuntimeOptions)2 UUID (java.util.UUID)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 BackendSupplier (io.cucumber.core.runtime.BackendSupplier)1 ObjectFactoryServiceLoader (io.cucumber.core.runtime.ObjectFactoryServiceLoader)1 ObjectFactorySupplier (io.cucumber.core.runtime.ObjectFactorySupplier)1 SingletonObjectFactorySupplier (io.cucumber.core.runtime.SingletonObjectFactorySupplier)1 SingletonRunnerSupplier (io.cucumber.core.runtime.SingletonRunnerSupplier)1