Search in sources :

Example 21 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished 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 22 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished in project cucumber-jvm by cucumber.

the class JUnitReporterWithStepNotificationsTest method ignores_steps_when_step_notification_are_disabled.

@Test
void ignores_steps_when_step_notification_are_disabled() {
    EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    JUnitReporter jUnitReporter = new JUnitReporter(bus, new JUnitOptionsBuilder().setStepNotifications(false).build());
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Result result = new Result(Status.PASSED, ZERO, null);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier, never()).fireTestStarted(pickleRunner.describeChild(step));
    verify(runNotifier, never()).fireTestFinished(pickleRunner.describeChild(step));
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 23 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished in project cucumber-jvm by cucumber.

the class JUnitReporterWithStepNotificationsTest method test_step_undefined_fires_test_failure_and_test_finished_for_undefined_step.

@Test
void test_step_undefined_fires_test_failure_and_test_finished_for_undefined_step() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    Suggestion suggestion = new Suggestion("step name", singletonList("some snippet"));
    bus.send(new SnippetsSuggestedEvent(now(), featureUri, scenarioLine, scenarioLine, suggestion));
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Throwable exception = new CucumberException("No step definitions found");
    Result result = new Result(Status.UNDEFINED, ZERO, exception);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
    verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure stepFailure = failureArgumentCaptor.getValue();
    assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
    assertThat(stepFailure.getException(), is(equalTo(exception)));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure pickleFailure = failureArgumentCaptor.getValue();
    assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.getException().getMessage(), is("" + "The step 'step name' is undefined.\n" + "You can implement this step using the snippet(s) below:\n" + "\n" + "some snippet\n"));
}
Also used : Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) SnippetsSuggestedEvent(io.cucumber.plugin.event.SnippetsSuggestedEvent) CucumberException(io.cucumber.core.exception.CucumberException) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) Failure(org.junit.runner.notification.Failure) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 24 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished in project cucumber-jvm by cucumber.

the class JUnitReporterWithStepNotificationsTest method test_step_finished_fires_test_failure_and_test_finished_for_skipped_step_with_pending_exception.

@Test
void test_step_finished_fires_test_failure_and_test_finished_for_skipped_step_with_pending_exception() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Throwable exception = new TestPendingException("Oops");
    Result result = new Result(Status.PENDING, ZERO, exception);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
    verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure stepFailure = failureArgumentCaptor.getValue();
    assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
    assertThat(stepFailure.getException(), is(equalTo(exception)));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure pickleFailure = failureArgumentCaptor.getValue();
    assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.getException(), is(equalTo(exception)));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) Failure(org.junit.runner.notification.Failure) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 25 with TestStepFinished

use of io.cucumber.plugin.event.TestStepFinished in project cucumber-jvm by cucumber.

the class JUnitReporterWithStepNotificationsTest method test_step_finished_fires_test_failure_and_test_finished_for_failed_step.

@Test
void test_step_finished_fires_test_failure_and_test_finished_for_failed_step() {
    jUnitReporter.startExecutionUnit(pickleRunner, runNotifier);
    bus.send(new TestCaseStarted(now(), testCase));
    bus.send(new TestStepStarted(now(), testCase, mockTestStep(step)));
    Throwable exception = new Exception("Oops");
    Result result = new Result(Status.FAILED, ZERO, exception);
    bus.send(new TestStepFinished(now(), testCase, mockTestStep(step), result));
    verify(runNotifier).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure stepFailure = failureArgumentCaptor.getValue();
    assertThat(stepFailure.getDescription(), is(equalTo(pickleRunner.describeChild(step))));
    assertThat(stepFailure.getException(), is(equalTo(exception)));
    bus.send(new TestCaseFinished(now(), testCase, result));
    verify(runNotifier, times(2)).fireTestFailure(failureArgumentCaptor.capture());
    verify(runNotifier).fireTestFinished(pickleRunner.describeChild(step));
    Failure pickleFailure = failureArgumentCaptor.getValue();
    assertThat(pickleFailure.getDescription(), is(equalTo(pickleRunner.getDescription())));
    assertThat(pickleFailure.getException(), is(equalTo(exception)));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) MultipleFailureException(org.junit.runners.model.MultipleFailureException) AssumptionViolatedException(org.junit.AssumptionViolatedException) CucumberException(io.cucumber.core.exception.CucumberException) Failure(org.junit.runner.notification.Failure) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Aggregations

TestStepFinished (io.cucumber.plugin.event.TestStepFinished)33 Result (io.cucumber.plugin.event.Result)31 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)24 Test (org.junit.jupiter.api.Test)24 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)17 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)16 Test (org.testng.annotations.Test)8 Failure (org.junit.runner.notification.Failure)7 SkipException (org.testng.SkipException)7 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)6 Arrays.asList (java.util.Arrays.asList)6 Collections.singletonList (java.util.Collections.singletonList)6 List (java.util.List)6 UUID (java.util.UUID)6 EventBus (io.cucumber.core.eventbus.EventBus)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 CucumberException (io.cucumber.core.exception.CucumberException)4 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)4 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)4 TestCase (io.cucumber.plugin.event.TestCase)4