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);
}
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"));
}
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"));
}
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"));
}
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"));
}
Aggregations