Search in sources :

Example 1 with RuntimeOptions

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

the class ThreadLocalRunnerSupplierTest method before.

@BeforeEach
void before() {
    Supplier<ClassLoader> classLoader = ThreadLocalRunnerSupplierTest.class::getClassLoader;
    RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
    ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(classLoader, runtimeOptions);
    ObjectFactorySupplier objectFactory = new SingletonObjectFactorySupplier(objectFactoryServiceLoader);
    BackendServiceLoader backendSupplier = new BackendServiceLoader(classLoader, objectFactory);
    eventBus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    runnerSupplier = new ThreadLocalRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactory);
}
Also used : RuntimeOptions(io.cucumber.core.options.RuntimeOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with RuntimeOptions

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

the class SingletonRunnerSupplierTest method before.

@BeforeEach
void before() {
    Supplier<ClassLoader> classLoader = SingletonRunnerSupplier.class::getClassLoader;
    RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
    ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(classLoader, runtimeOptions);
    ObjectFactorySupplier objectFactory = new SingletonObjectFactorySupplier(objectFactoryServiceLoader);
    BackendServiceLoader backendSupplier = new BackendServiceLoader(getClass()::getClassLoader, objectFactory);
    EventBus eventBus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    runnerSupplier = new SingletonRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactory);
}
Also used : EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with RuntimeOptions

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

the class PluginsTest method shouldRegisterCanonicalOrderEventPublisherWithRootEventPublisher.

@Test
void shouldRegisterCanonicalOrderEventPublisherWithRootEventPublisher() {
    RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
    Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
    EventListener plugin = mock(EventListener.class);
    plugins.addPlugin(plugin);
    plugins.setSerialEventBusOnEventListenerPlugins(rootEventPublisher);
    verify(rootEventPublisher, times(1)).registerHandlerFor(eq(Event.class), ArgumentMatchers.any());
}
Also used : Event(io.cucumber.plugin.event.Event) ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) EventListener(io.cucumber.plugin.EventListener) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) Test(org.junit.jupiter.api.Test)

Example 4 with RuntimeOptions

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

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

the class Main method run.

/**
 * Launches the Cucumber-JVM command line.
 *
 * @param  argv        runtime options. See details in the
 *                     {@code cucumber.api.cli.Usage.txt} resource.
 * @param  classLoader classloader used to load the runtime
 * @return             0 if execution was successful, 1 if it was not (test
 *                     failures)
 */
public static byte run(String[] argv, ClassLoader classLoader) {
    RuntimeOptions propertiesFileOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromPropertiesFile()).build();
    RuntimeOptions environmentOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromEnvironment()).build(propertiesFileOptions);
    RuntimeOptions systemOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromSystemProperties()).build(environmentOptions);
    CommandlineOptionsParser commandlineOptionsParser = new CommandlineOptionsParser(System.out);
    RuntimeOptions runtimeOptions = commandlineOptionsParser.parse(argv).addDefaultGlueIfAbsent().addDefaultFeaturePathIfAbsent().addDefaultSummaryPrinterIfNotDisabled().enablePublishPlugin().build(systemOptions);
    Optional<Byte> exitStatus = commandlineOptionsParser.exitStatus();
    if (exitStatus.isPresent()) {
        return exitStatus.get();
    }
    final Runtime runtime = Runtime.builder().withRuntimeOptions(runtimeOptions).withClassLoader(() -> classLoader).build();
    runtime.run();
    return runtime.exitStatus();
}
Also used : CucumberPropertiesParser(io.cucumber.core.options.CucumberPropertiesParser) Runtime(io.cucumber.core.runtime.Runtime) CommandlineOptionsParser(io.cucumber.core.options.CommandlineOptionsParser) RuntimeOptions(io.cucumber.core.options.RuntimeOptions)

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