Search in sources :

Example 6 with Suggestion

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

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

the class DefaultSummaryPrinterTest method does_not_print_duplicate_snippets.

@Test
void does_not_print_duplicate_snippets() {
    bus.send(new SnippetsSuggestedEvent(bus.getInstant(), URI.create("classpath:com/example.feature"), new Location(12, -1), new Location(13, -1), new Suggestion("", singletonList("snippet"))));
    bus.send(new SnippetsSuggestedEvent(bus.getInstant(), URI.create("classpath:com/example.feature"), new Location(12, -1), new Location(14, -1), new Suggestion("", singletonList("snippet"))));
    bus.send(new TestRunFinished(bus.getInstant(), new Result(Status.PASSED, Duration.ZERO, null)));
    assertThat(new String(out.toByteArray(), UTF_8), equalToCompressingWhiteSpace("" + "\n" + "0 Scenarios\n" + "0 Steps\n" + "0m0.000s\n" + "\n" + "\n" + "You can implement missing steps with the snippets below:\n" + "\n" + "snippet\n" + "\n" + "\n"));
}
Also used : Suggestion(io.cucumber.plugin.event.SnippetsSuggestedEvent.Suggestion) SnippetsSuggestedEvent(io.cucumber.plugin.event.SnippetsSuggestedEvent) TestRunFinished(io.cucumber.plugin.event.TestRunFinished) Location(io.cucumber.plugin.event.Location) Result(io.cucumber.plugin.event.Result) Test(org.junit.jupiter.api.Test)

Aggregations

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