Search in sources :

Example 26 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class ObjectFactoryServiceLoaderTest method shouldThrowIfSelectedObjectFactoryServiceCouldNotBeLoaded.

@Test
void shouldThrowIfSelectedObjectFactoryServiceCouldNotBeLoaded() {
    Options options = () -> NoSuchObjectFactory.class;
    Supplier<ClassLoader> classLoader = () -> new FilteredClassLoader("META-INF/services/io.cucumber.core.backend.ObjectFactory");
    ObjectFactoryServiceLoader loader = new ObjectFactoryServiceLoader(classLoader, options);
    CucumberException exception = assertThrows(CucumberException.class, loader::loadObjectFactory);
    assertThat(exception.getMessage(), is("" + "Could not find object factory io.cucumber.core.runtime.ObjectFactoryServiceLoaderTest$NoSuchObjectFactory.\n" + "\n" + "Cucumber uses SPI to discover object factory implementations.\n" + "Has the class been registered with SPI and is it available on\n" + "the classpath?"));
}
Also used : Options(io.cucumber.core.backend.Options) URLClassLoader(java.net.URLClassLoader) CucumberException(io.cucumber.core.exception.CucumberException) Test(org.junit.jupiter.api.Test)

Example 27 with CucumberException

use of io.cucumber.core.exception.CucumberException 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 28 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class CucumberPropertiesParser method parseAll.

private <T> void parseAll(CucumberPropertiesProvider properties, String propertyName, Function<String, Collection<T>> parser, Consumer<T> setter) {
    String property = properties.get(propertyName);
    if (property == null || property.isEmpty()) {
        return;
    }
    try {
        Collection<T> parsed = parser.apply(property);
        parsed.forEach(setter);
    } catch (Exception e) {
        throw new CucumberException("Failed to parse '" + propertyName + "' with value '" + property + "'", e);
    }
}
Also used : CucumberException(io.cucumber.core.exception.CucumberException) CucumberException(io.cucumber.core.exception.CucumberException)

Example 29 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class PrettyFormatter method printStep.

private void printStep(TestStepFinished event) {
    if (event.getTestStep() instanceof PickleStepTestStep) {
        PickleStepTestStep testStep = (PickleStepTestStep) event.getTestStep();
        String keyword = testStep.getStep().getKeyword();
        String stepText = testStep.getStep().getText();
        String status = event.getResult().getStatus().name().toLowerCase(ROOT);
        String formattedStepText = formatStepText(keyword, stepText, formats.get(status), formats.get(status + "_arg"), testStep.getDefinitionArgument());
        String locationComment = formatLocationComment(event, testStep, keyword, stepText);
        out.println(STEP_INDENT + formattedStepText + locationComment);
        StepArgument stepArgument = testStep.getStep().getArgument();
        if (DataTableArgument.class.isInstance(stepArgument)) {
            DataTableFormatter tableFormatter = DataTableFormatter.builder().prefixRow(STEP_SCENARIO_INDENT).escapeDelimiters(false).build();
            DataTableArgument dataTableArgument = (DataTableArgument) stepArgument;
            try {
                tableFormatter.formatTo(DataTable.create(dataTableArgument.cells()), out);
            } catch (IOException e) {
                throw new CucumberException(e);
            }
        }
    }
}
Also used : DataTableFormatter(io.cucumber.datatable.DataTableFormatter) PickleStepTestStep(io.cucumber.plugin.event.PickleStepTestStep) StepArgument(io.cucumber.plugin.event.StepArgument) DataTableArgument(io.cucumber.core.gherkin.DataTableArgument) IOException(java.io.IOException) CucumberException(io.cucumber.core.exception.CucumberException)

Example 30 with CucumberException

use of io.cucumber.core.exception.CucumberException in project cucumber-jvm by cucumber.

the class DefaultObjectFactoryTest method shouldThrowForNonZeroArgPublicConstructors.

@Test
void shouldThrowForNonZeroArgPublicConstructors() {
    CucumberException exception = assertThrows(CucumberException.class, () -> factory.getInstance(NoAccessibleConstructor.class));
    assertThat(exception.getMessage(), is("" + "class io.cucumber.core.backend.DefaultObjectFactoryTest$NoAccessibleConstructor does not have a public zero-argument constructor.\n" + "\n" + "To use dependency injection add an other ObjectFactory implementation such as:\n" + " * cucumber-picocontainer\n" + " * cucumber-spring\n" + " * cucumber-jakarta-cdi\n" + " * ...etc\n"));
}
Also used : CucumberException(io.cucumber.core.exception.CucumberException) Test(org.junit.jupiter.api.Test)

Aggregations

CucumberException (io.cucumber.core.exception.CucumberException)39 Test (org.junit.jupiter.api.Test)28 Executable (org.junit.jupiter.api.function.Executable)19 StepDefinition (io.cucumber.core.backend.StepDefinition)12 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)12 Feature (io.cucumber.core.gherkin.Feature)11 Step (io.cucumber.core.gherkin.Step)11 Argument (io.cucumber.core.stepexpression.Argument)11 StepExpression (io.cucumber.core.stepexpression.StepExpression)8 PluginOption (io.cucumber.core.options.PluginOption)5 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)4 IOException (java.io.IOException)3 URI (java.net.URI)3 Options (io.cucumber.core.backend.Options)2 DataTableType (io.cucumber.datatable.DataTableType)2 File (java.io.File)2 InputStream (java.io.InputStream)2 URLClassLoader (java.net.URLClassLoader)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2