Search in sources :

Example 1 with SnippetsSuggestedEvent

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

the class Runner method emitSnippetSuggestedEvent.

private void emitSnippetSuggestedEvent(Pickle pickle, Step step) {
    List<String> snippets = generateSnippetsForStep(step);
    if (snippets.isEmpty()) {
        return;
    }
    Suggestion suggestion = new Suggestion(step.getText(), snippets);
    Location scenarioLocation = pickle.getLocation();
    Location stepLocation = step.getLocation();
    SnippetsSuggestedEvent event = new SnippetsSuggestedEvent(bus.getInstant(), pickle.getUri(), scenarioLocation, stepLocation, suggestion);
    bus.send(event);
}
Also used : Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) SnippetsSuggestedEvent(io.cucumber.plugin.event.SnippetsSuggestedEvent) Location(io.cucumber.plugin.event.Location)

Example 2 with SnippetsSuggestedEvent

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

the class TestCaseResultObserverTest method should_be_failed_for_undefined_result.

@Test
public void should_be_failed_for_undefined_result() {
    TestCaseResultObserver resultListener = TestCaseResultObserver.observe(bus);
    bus.send(new SnippetsSuggestedEvent(now(), uri, location, location, new 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 3 with SnippetsSuggestedEvent

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

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

use of io.cucumber.plugin.event.SnippetsSuggestedEvent 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)

Aggregations

SnippetsSuggestedEvent (io.cucumber.plugin.event.SnippetsSuggestedEvent)6 Suggestion (io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion)6 Result (io.cucumber.plugin.event.Result)5 TestCaseFinished (io.cucumber.plugin.event.TestCaseFinished)4 TestStepFinished (io.cucumber.plugin.event.TestStepFinished)4 Test (org.junit.jupiter.api.Test)3 Location (io.cucumber.plugin.event.Location)2 TestCaseStarted (io.cucumber.plugin.event.TestCaseStarted)2 TestStepStarted (io.cucumber.plugin.event.TestStepStarted)2 SkipException (org.testng.SkipException)2 Test (org.testng.annotations.Test)2 CucumberException (io.cucumber.core.exception.CucumberException)1 TestRunFinished (io.cucumber.plugin.event.TestRunFinished)1 Failure (org.junit.runner.notification.Failure)1 TestAbortedException (org.opentest4j.TestAbortedException)1