Search in sources :

Example 6 with RuntimeOptions

use of io.cucumber.core.options.RuntimeOptions in project cucumber-jvm by cucumber.

the class RunnerTest method hooks_not_executed_in_dry_run_mode.

@Test
void hooks_not_executed_in_dry_run_mode() {
    RuntimeOptions runtimeOptions = new RuntimeOptionsBuilder().setDryRun().build();
    StaticHookDefinition beforeAllHook = createStaticHook();
    StaticHookDefinition afterAllHook = createStaticHook();
    HookDefinition beforeHook = createHook();
    HookDefinition afterHook = createHook();
    HookDefinition beforeStepHook = createHook();
    HookDefinition afterStepHook = createHook();
    TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            glue.addBeforeAllHook(beforeAllHook);
            glue.addAfterAllHook(afterAllHook);
            glue.addBeforeHook(beforeHook);
            glue.addAfterHook(afterHook);
            glue.addBeforeStepHook(beforeStepHook);
            glue.addAfterStepHook(afterStepHook);
        }
    };
    runnerSupplier.get().runBeforeAllHooks();
    runnerSupplier.get().runPickle(createPicklesWithSteps());
    runnerSupplier.get().runAfterAllHooks();
    verify(beforeAllHook, never()).execute();
    verify(afterAllHook, never()).execute();
    verify(beforeHook, never()).execute(any(TestCaseState.class));
    verify(afterHook, never()).execute(any(TestCaseState.class));
    verify(beforeStepHook, never()).execute(any(TestCaseState.class));
    verify(afterStepHook, never()).execute(any(TestCaseState.class));
}
Also used : Glue(io.cucumber.core.backend.Glue) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StaticHookDefinition(io.cucumber.core.backend.StaticHookDefinition) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) StaticHookDefinition(io.cucumber.core.backend.StaticHookDefinition) HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Example 7 with RuntimeOptions

use of io.cucumber.core.options.RuntimeOptions in project cucumber-jvm by cucumber.

the class RunnerTest method steps_are_not_executed_on_dry_run.

@Test
void steps_are_not_executed_on_dry_run() {
    StubStepDefinition stepDefinition = new StubStepDefinition("some step");
    Pickle pickle = createPickleMatchingStepDefinitions(stepDefinition);
    RuntimeOptions runtimeOptions = new RuntimeOptionsBuilder().setDryRun().build();
    TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            glue.addStepDefinition(stepDefinition);
        }
    };
    runnerSupplier.get().runPickle(pickle);
    assertThat(stepDefinition.getArgs(), is(nullValue()));
}
Also used : Pickle(io.cucumber.core.gherkin.Pickle) Glue(io.cucumber.core.backend.Glue) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Test(org.junit.jupiter.api.Test)

Example 8 with RuntimeOptions

use of io.cucumber.core.options.RuntimeOptions 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 9 with RuntimeOptions

use of io.cucumber.core.options.RuntimeOptions 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)

Example 10 with RuntimeOptions

use of io.cucumber.core.options.RuntimeOptions in project cucumber-jvm by cucumber.

the class PluginsTest method shouldSetConcurrentEventListener.

@Test
void shouldSetConcurrentEventListener() {
    RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
    Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
    ConcurrentEventListener plugin = mock(ConcurrentEventListener.class);
    plugins.addPlugin(plugin);
    plugins.setEventBusOnEventListenerPlugins(rootEventPublisher);
    verify(plugin, times(1)).setEventPublisher(rootEventPublisher);
}
Also used : RuntimeOptions(io.cucumber.core.options.RuntimeOptions) ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) Test(org.junit.jupiter.api.Test)

Aggregations

RuntimeOptions (io.cucumber.core.options.RuntimeOptions)13 Test (org.junit.jupiter.api.Test)9 UUID (java.util.UUID)4 EventBus (io.cucumber.core.eventbus.EventBus)3 Filters (io.cucumber.core.filter.Filters)3 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)3 CucumberExecutionContext (io.cucumber.core.runtime.CucumberExecutionContext)3 ExitStatus (io.cucumber.core.runtime.ExitStatus)3 ThreadLocalRunnerSupplier (io.cucumber.core.runtime.ThreadLocalRunnerSupplier)3 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)3 ConcurrentEventListener (io.cucumber.plugin.ConcurrentEventListener)3 Glue (io.cucumber.core.backend.Glue)2 Feature (io.cucumber.core.gherkin.Feature)2 RunnerSupplier (io.cucumber.core.runtime.RunnerSupplier)2 EventListener (io.cucumber.plugin.EventListener)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 HookDefinition (io.cucumber.core.backend.HookDefinition)1