Search in sources :

Example 16 with TestStepFinished

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

the class TestCaseResultObserverTest method should_not_be_skipped_for_undefined_result.

@Test
public void should_not_be_skipped_for_undefined_result() {
    TestCaseResultObserver resultListener = TestCaseResultObserver.observe(bus);
    bus.send(new SnippetsSuggestedEvent(now(), uri, location, location, new SnippetsSuggestedEvent.Suggestion("some step", singletonList("stub snippet"))));
    Result stepResult = new Result(UNDEFINED, ZERO, error);
    bus.send(new TestStepFinished(now(), testCase, step, stepResult));
    Result testCaseResult = new Result(UNDEFINED, ZERO, error);
    bus.send(new TestCaseFinished(now(), testCase, testCaseResult));
    Exception exception = expectThrows(Exception.class, resultListener::assertTestCasePassed);
    assertThat(exception.getCause(), instanceOf(SkipException.class));
    SkipException skipException = (SkipException) exception.getCause();
    assertThat(skipException.isSkip(), is(false));
    assertThat(skipException.getMessage(), is("" + "The step 'some step' is undefined.\n" + "You can implement this step using the snippet(s) below:\n" + "\n" + "stub 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) SkipException(org.testng.SkipException) SkipException(org.testng.SkipException) Result(io.cucumber.plugin.event.Result) Test(org.testng.annotations.Test)

Example 17 with TestStepFinished

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

the class TestCaseResultObserverTest method undefined.

@Test
void undefined() {
    bus.send(new TestCaseStarted(Instant.now(), testCase));
    bus.send(new TestStepStarted(Instant.now(), testCase, testStep));
    bus.send(new SnippetsSuggestedEvent(Instant.now(), uri, testCase.getLocation(), testStep.getStep().getLocation(), new Suggestion(testStep.getStep().getText(), asList("mocked snippet 1", "mocked snippet 2", "mocked snippet 3"))));
    Result result = new Result(Status.UNDEFINED, Duration.ZERO, null);
    bus.send(new TestStepFinished(Instant.now(), testCase, testStep, result));
    bus.send(new TestCaseFinished(Instant.now(), testCase, result));
    Exception exception = assertThrows(Exception.class, observer::assertTestCasePassed);
    assertThat(exception.getCause(), instanceOf(UndefinedStepException.class));
    assertThat(exception.getCause().getMessage(), is("" + "The step 'mocked' is undefined.\n" + "You can implement this step using the snippet(s) below:\n" + "\n" + "mocked snippet 1\n" + "mocked snippet 2\n" + "mocked snippet 3\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) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) TestAbortedException(org.opentest4j.TestAbortedException) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 18 with TestStepFinished

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

the class TestCaseResultObserverTest method passed.

@Test
void passed() {
    bus.send(new TestCaseStarted(Instant.now(), testCase));
    bus.send(new TestStepStarted(Instant.now(), testCase, testStep));
    Result result = new Result(Status.PASSED, Duration.ZERO, null);
    bus.send(new TestStepFinished(Instant.now(), testCase, testStep, result));
    bus.send(new TestCaseFinished(Instant.now(), testCase, result));
    observer.assertTestCasePassed();
}
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) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 19 with TestStepFinished

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

the class TestCaseResultObserverTest method failed.

@Test
void failed() {
    bus.send(new TestCaseStarted(Instant.now(), testCase));
    bus.send(new TestStepStarted(Instant.now(), testCase, testStep));
    Throwable error = new AssertionFailedError("Mocked");
    Result result = new Result(Status.FAILED, Duration.ZERO, error);
    bus.send(new TestStepFinished(Instant.now(), testCase, testStep, result));
    bus.send(new TestCaseFinished(Instant.now(), testCase, result));
    Exception exception = assertThrows(Exception.class, observer::assertTestCasePassed);
    assertThat(exception.getCause(), is(error));
}
Also used : TestCaseFinished(io.cucumber.plugin.event.TestCaseFinished) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) AssertionFailedError(org.opentest4j.AssertionFailedError) TestStepStarted(io.cucumber.plugin.event.TestStepStarted) TestCaseStarted(io.cucumber.plugin.event.TestCaseStarted) TestAbortedException(org.opentest4j.TestAbortedException) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Example 20 with TestStepFinished

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

the class EventBusTest method handlers_receive_the_events_they_registered_for.

@Test
void handlers_receive_the_events_they_registered_for() {
    EventHandler<TestStepFinished> handler = mock(EventHandler.class);
    PickleStepTestStep testStep = mock(PickleStepTestStep.class);
    Result result = new Result(Status.PASSED, ZERO, null);
    TestCase testCase = mock(TestCase.class);
    TestStepFinished event = new TestStepFinished(EPOCH, testCase, testStep, result);
    EventBus bus = new TimeServiceEventBus(Clock.fixed(Instant.EPOCH, ZoneId.of("UTC")), UUID::randomUUID);
    bus.registerHandlerFor(TestStepFinished.class, handler);
    bus.send(event);
    verify(handler).receive(event);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) TestStepFinished(io.cucumber.plugin.event.TestStepFinished) TestCase(io.cucumber.plugin.event.TestCase) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) EventBus(io.cucumber.core.eventbus.EventBus) UUID(java.util.UUID) 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