Search in sources :

Example 6 with Result

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

the class PickleStepTestStepTest method result_is_result_from_hook_when_after_step_hook_does_not_pass.

@Test
void result_is_result_from_hook_when_after_step_hook_does_not_pass() {
    Exception exception = new RuntimeException();
    Result failure = new Result(Status.FAILED, ZERO, exception);
    doThrow(exception).when(afterHookDefinition).execute(any(TestCaseState.class));
    ExecutionMode nextExecutionMode = step.run(testCase, bus, state, ExecutionMode.RUN);
    assertThat(nextExecutionMode, is(ExecutionMode.SKIP));
    assertThat(state.getStatus(), is(equalTo(FAILED)));
    ArgumentCaptor<Object> captor = forClass(TestCaseEvent.class);
    verify(bus, times(12)).send(captor.capture());
    List<Object> allValues = captor.getAllValues();
    assertThat(((TestStepFinished) allValues.get(10)).getResult(), is(equalTo(failure)));
}
Also used : StubPendingException(io.cucumber.core.backend.StubPendingException) TestAbortedException(org.opentest4j.TestAbortedException) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 7 with Result

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

the class PluginFactoryTest method plugin_does_not_buffer_its_output.

@Test
void plugin_does_not_buffer_its_output() {
    PrintStream previousSystemOut = System.out;
    OutputStream mockSystemOut = new ByteArrayOutputStream();
    try {
        System.setOut(new PrintStream(mockSystemOut));
        // Need to create a new plugin factory here since we need it to pick
        // up the new value of System.out
        fc = new PluginFactory();
        PluginOption option = parse("progress");
        ProgressFormatter plugin = (ProgressFormatter) fc.create(option);
        EventBus bus = new TimeServiceEventBus(new ClockStub(ZERO), UUID::randomUUID);
        plugin.setEventPublisher(bus);
        Result result = new Result(Status.PASSED, ZERO, null);
        TestStepFinished event = new TestStepFinished(bus.getInstant(), mock(TestCase.class), mock(PickleStepTestStep.class), result);
        bus.send(event);
        assertThat(mockSystemOut.toString(), is(not(equalTo(""))));
    } finally {
        System.setOut(previousSystemOut);
    }
}
Also used : PrintStream(java.io.PrintStream) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ClockStub(io.cucumber.core.runner.ClockStub) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EventBus(io.cucumber.core.eventbus.EventBus) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) Result(io.cucumber.plugin.event.Result) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) PluginOption(io.cucumber.core.options.PluginOption) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 8 with Result

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

the class TestCaseStateResultTest method passed_and_skipped_is_skipped_although_we_cant_have_skipped_without_undefined_or_pending.

@Test
void passed_and_skipped_is_skipped_although_we_cant_have_skipped_without_undefined_or_pending() {
    s.add(new Result(Status.PASSED, ZERO, null));
    s.add(new Result(Status.SKIPPED, ZERO, null));
    assertAll(() -> assertThat(s.getStatus(), is(equalTo(SKIPPED))), () -> assertFalse(s.isFailed()));
}
Also used : Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 9 with Result

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

the class TestCaseStateResultTest method passed_undefined_skipped_is_undefined.

@Test
void passed_undefined_skipped_is_undefined() {
    s.add(new Result(Status.PASSED, ZERO, null));
    s.add(new Result(Status.UNDEFINED, ZERO, null));
    s.add(new Result(Status.SKIPPED, ZERO, null));
    assertAll(() -> assertThat(s.getStatus(), is(equalTo(UNDEFINED))), () -> assertFalse(s.isFailed()));
}
Also used : Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 10 with Result

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

the class CucumberExecutionContextTest method emits_failures_in_events.

@Test
public void emits_failures_in_events() {
    List<TestRunStarted> testRunStarted = new ArrayList<>();
    List<TestRunFinished> testRunFinished = new ArrayList<>();
    bus.registerHandlerFor(TestRunStarted.class, testRunStarted::add);
    bus.registerHandlerFor(TestRunFinished.class, testRunFinished::add);
    context.startTestRun();
    assertThrows(IllegalStateException.class, () -> context.runTestCase(runner -> {
        throw failure;
    }));
    context.finishTestRun();
    assertThat(testRunStarted.get(0), notNullValue());
    Result result = testRunFinished.get(0).getResult();
    assertThat(result.getStatus(), is(Status.FAILED));
    assertThat(result.getError(), is(failure));
}
Also used : TestRunStarted(io.cucumber.plugin.event.TestRunStarted) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Result(io.cucumber.plugin.event.Result) TestRunStarted(io.cucumber.plugin.event.TestRunStarted) Status(io.cucumber.plugin.event.Status) UUID(java.util.UUID) TestCase(io.cucumber.plugin.event.TestCase) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) RuntimeOptions(io.cucumber.core.options.RuntimeOptions) List(java.util.List) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) Duration(java.time.Duration) Clock(java.time.Clock) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) EventBus(io.cucumber.core.eventbus.EventBus) Mockito.mock(org.mockito.Mockito.mock) ArrayList(java.util.ArrayList) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Aggregations

Result (io.cucumber.plugin.event.Result)56 Test (org.junit.jupiter.api.Test)41 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)29 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)26 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)15 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)14 Test (org.testng.annotations.Test)9 UUID (java.util.UUID)7 Failure (org.junit.runner.notification.Failure)7 SkipException (org.testng.SkipException)7 PickleStepTestStep (io.cucumber.plugin.event.PickleStepTestStep)6 Status (io.cucumber.plugin.event.Status)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 List (java.util.List)6 TestAbortedException (org.opentest4j.TestAbortedException)6 EventBus (io.cucumber.core.eventbus.EventBus)5 SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)5 Suggestion (io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion)5 TestRunFinished (io.cucumber.plugin.event.TestRunFinished)5 OutputStream (java.io.OutputStream)5