Search in sources :

Example 16 with RuntimeOptionsBuilder

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

the class RuntimeTest method should_interrupt_waiting_plugins.

@Test
void should_interrupt_waiting_plugins() throws InterruptedException {
    final Feature feature1 = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name 1\n" + "  Scenario: scenario_1 name\n" + "    Given first step\n" + "  Scenario: scenario_2 name\n" + "    Given first step\n");
    final Feature feature2 = TestFeatureParser.parse("path/test2.feature", "" + "Feature: feature name 2\n" + "  Scenario: scenario_2 name\n" + "    Given first step\n");
    final CountDownLatch threadBlocked = new CountDownLatch(1);
    final CountDownLatch interruptHit = new CountDownLatch(1);
    final ConcurrentEventListener brokenEventListener = publisher -> publisher.registerHandlerFor(TestStepFinished.class, (TestStepFinished event) -> {
        try {
            threadBlocked.countDown();
            HOURS.sleep(1);
        } catch (InterruptedException ignored) {
            interruptHit.countDown();
        }
    });
    Thread thread = new Thread(() -> Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2)).withAdditionalPlugins(brokenEventListener).withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(2).build()).build().run());
    thread.start();
    threadBlocked.await(1, SECONDS);
    thread.interrupt();
    interruptHit.await(1, SECONDS);
    assertThat(interruptHit.getCount(), is(equalTo(0L)));
}
Also used : ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Meta(io.cucumber.messages.types.Meta) Status(io.cucumber.plugin.event.Status) ScenarioScoped(io.cucumber.core.backend.ScenarioScoped) Collections.singletonList(java.util.Collections.singletonList) StepDefinedEvent(io.cucumber.plugin.event.StepDefinedEvent) Arrays.asList(java.util.Arrays.asList) CompositeCucumberException(io.cucumber.core.exception.CompositeCucumberException) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) TestBackendSupplier(io.cucumber.core.runner.TestBackendSupplier) HookDefinition(io.cucumber.core.backend.HookDefinition) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Envelope(io.cucumber.messages.types.Envelope) Result(io.cucumber.plugin.event.Result) Collections.emptyList(java.util.Collections.emptyList) Glue(io.cucumber.core.backend.Glue) UUID(java.util.UUID) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Matchers.matchesPattern(org.hamcrest.Matchers.matchesPattern) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) ZERO(java.time.Duration.ZERO) Mockito.mock(org.mockito.Mockito.mock) Plugin(io.cucumber.plugin.Plugin) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Matchers.arrayWithSize(org.hamcrest.Matchers.arrayWithSize) StepDefinition(io.cucumber.plugin.event.StepDefinition) ZoneId.of(java.time.ZoneId.of) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) EventListener(io.cucumber.plugin.EventListener) ArrayList(java.util.ArrayList) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) ArgumentCaptor(org.mockito.ArgumentCaptor) ParameterInfo(io.cucumber.core.backend.ParameterInfo) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestCaseState(io.cucumber.core.backend.TestCaseState) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) EventPublisher(io.cucumber.plugin.event.EventPublisher) EventBus(io.cucumber.core.eventbus.EventBus) Clock.fixed(java.time.Clock.fixed) TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Clock(java.time.Clock) HOURS(java.util.concurrent.TimeUnit.HOURS) EPOCH(java.time.Instant.EPOCH) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) Feature(io.cucumber.core.gherkin.Feature) ConcurrentEventListener(io.cucumber.plugin.ConcurrentEventListener) Test(org.junit.jupiter.api.Test)

Example 17 with RuntimeOptionsBuilder

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

the class RuntimeTest method should_call_formatter_with_correct_sequence_of_events_when_running_in_parallel.

@Test
void should_call_formatter_with_correct_sequence_of_events_when_running_in_parallel() {
    Feature feature1 = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name 1\n" + "  Scenario: scenario_1 name\n" + "    Given first step\n" + "  Scenario: scenario_2 name\n" + "    Given first step\n");
    Feature feature2 = TestFeatureParser.parse("path/test2.feature", "" + "Feature: feature name 2\n" + "  Scenario: scenario_2 name\n" + "    Given first step\n");
    Feature feature3 = TestFeatureParser.parse("path/test3.feature", "" + "Feature: feature name 3\n" + "  Scenario: scenario_3 name\n" + "    Given first step\n");
    FormatterSpy formatterSpy = new FormatterSpy();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2, feature3)).withAdditionalPlugins(formatterSpy).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step"))).withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(3).build()).build().run();
    String formatterOutput = formatterSpy.toString();
    assertThat(formatterOutput, is(equalTo("" + "TestRun started\n" + "  TestCase started\n" + "    TestStep started\n" + "    TestStep finished\n" + "  TestCase finished\n" + "  TestCase started\n" + "    TestStep started\n" + "    TestStep finished\n" + "  TestCase finished\n" + "  TestCase started\n" + "    TestStep started\n" + "    TestStep finished\n" + "  TestCase finished\n" + "  TestCase started\n" + "    TestStep started\n" + "    TestStep finished\n" + "  TestCase finished\n" + "TestRun finished\n")));
}
Also used : RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 18 with RuntimeOptionsBuilder

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

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

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

the class DryRunTest method dry_run_skips_all_steps_after_ambiguous_step.

@Test
void dry_run_skips_all_steps_after_ambiguous_step() {
    StepStatusSpy out = new StepStatusSpy();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(ambiguous)).withAdditionalPlugins(out).withBackendSupplier(backend).withRuntimeOptions(new RuntimeOptionsBuilder().setDryRun().build()).build().run();
    assertThat(out.toString(), is("" + "ambiguous\n" + "    AMBIGUOUS\n" + "    SKIPPED\n" + "    SKIPPED\n" + "    SKIPPED\n" + "    SKIPPED\n" + "    SKIPPED\n" + "    SKIPPED\n"));
}
Also used : RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)28 Test (org.junit.jupiter.api.Test)27 Feature (io.cucumber.core.gherkin.Feature)20 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)13 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)13 Collections.emptyList (java.util.Collections.emptyList)7 Collections.singletonList (java.util.Collections.singletonList)7 EventBus (io.cucumber.core.eventbus.EventBus)6 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)6 UUID (java.util.UUID)6 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)5 TestFeatureParser (io.cucumber.core.feature.TestFeatureParser)5 Clock (java.time.Clock)5 Arrays.asList (java.util.Arrays.asList)5 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)5 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)5 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)5 Glue (io.cucumber.core.backend.Glue)4