Search in sources :

Example 1 with CucumberBackendException

use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method throws_could_not_invoke_argument_conversion_when_argument_could_not_be_got.

@Test
void throws_could_not_invoke_argument_conversion_when_argument_could_not_be_got() {
    Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have a data table\n" + "       | A | \n");
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have a data table", UndefinedDataTableType.class);
    List<Argument> arguments = Collections.singletonList(() -> {
        throw new CucumberBackendException("This exception is expected", new IllegalAccessException());
    });
    StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, URI.create("file:path/to.feature"), step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
    assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have a data table] defined at '{stubbed location with details}'.\n" + "It appears there was a problem with a hook or transformer definition.")));
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Step(io.cucumber.core.gherkin.Step) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 2 with CucumberBackendException

use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method throws_could_not_invoke_step_when_execution_failed_due_to_bad_methods.

@Test
void throws_could_not_invoke_step_when_execution_failed_due_to_bad_methods() {
    Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have a data table\n" + "       | A | \n" + "       | B | \n");
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have a data table", new CucumberBackendException("This exception is expected!", new IllegalAccessException()), String.class, String.class);
    List<Argument> arguments = asList(() -> "mocked table cell", () -> "mocked table cell");
    StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, URI.create("file:path/to.feature"), step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
    assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not invoke step [I have a data table] defined at '{stubbed location with details}'.\n" + "It appears there was a problem with the step definition.\n" + "The converted arguments types were (java.lang.String, java.lang.String)")));
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Step(io.cucumber.core.gherkin.Step) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 3 with CucumberBackendException

use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldFailIfClassWithSpringComponentAnnotationsIsFound.

@Test
void shouldFailIfClassWithSpringComponentAnnotationsIsFound() {
    final ObjectFactory factory = new SpringFactory();
    Executable testMethod = () -> factory.addClass(WithComponentAnnotation.class);
    CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
    assertThat(actualThrown.getMessage(), is(equalTo("Glue class io.cucumber.spring.componentannotation.WithComponentAnnotation was annotated with @Component; marking it as a candidate for auto-detection by Spring. Glue classes are detected and registered by Cucumber. Auto-detection of glue classes by spring may lead to duplicate bean definitions. Please remove the @Component annotation")));
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 4 with CucumberBackendException

use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldFailIfMultipleClassesWithSpringAnnotationsAreFound.

@Test
void shouldFailIfMultipleClassesWithSpringAnnotationsAreFound() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(WithSpringAnnotations.class);
    Executable testMethod = () -> factory.addClass(BellyStepDefinitions.class);
    CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
    assertThat(actualThrown.getMessage(), startsWith("Glue class class io.cucumber.spring.contextconfig.BellyStepDefinitions and class io.cucumber.spring.SpringFactoryTest$WithSpringAnnotations are both annotated with @CucumberContextConfiguration.\n" + "Please ensure only one class configures the spring context"));
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 5 with CucumberBackendException

use of io.cucumber.core.backend.CucumberBackendException in project cucumber-jvm by cucumber.

the class SpringFactory method start.

@Override
public void start() {
    if (withCucumberContextConfiguration == null) {
        throw new CucumberBackendException("" + "Please annotate a glue class with some context configuration.\n" + "\n" + "For example:\n" + "\n" + "   @CucumberContextConfiguration\n" + "   @SpringBootTest(classes = TestConfig.class)\n" + "   public class CucumberSpringConfiguration { }" + "\n" + "Or: \n" + "\n" + "   @CucumberContextConfiguration\n" + "   @ContextConfiguration( ... )\n" + "   public class CucumberSpringConfiguration { }");
    }
    // The application context created by the TestContextManager is
    // a singleton and reused between scenarios and shared between
    // threads.
    TestContextManager testContextManager = new TestContextManager(withCucumberContextConfiguration);
    testContextAdaptor = createTestContextManagerAdaptor(testContextManager, stepClasses);
    testContextAdaptor.start();
}
Also used : CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) TestContextManager(org.springframework.test.context.TestContextManager)

Aggregations

CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)17 Test (org.junit.jupiter.api.Test)9 Executable (org.junit.jupiter.api.function.Executable)9 Argument (io.cucumber.core.stepexpression.Argument)4 ObjectFactory (io.cucumber.core.backend.ObjectFactory)3 StepDefinition (io.cucumber.core.backend.StepDefinition)3 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)3 CucumberException (io.cucumber.core.exception.CucumberException)3 Feature (io.cucumber.core.gherkin.Feature)3 Step (io.cucumber.core.gherkin.Step)3 Method (java.lang.reflect.Method)2 List (java.util.List)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Is.is (org.hamcrest.core.Is.is)2 Is.isA (org.hamcrest.core.Is.isA)2 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 CucumberInvocationTargetException (io.cucumber.core.backend.CucumberInvocationTargetException)1 ParameterInfo (io.cucumber.core.backend.ParameterInfo)1 CucumberExpressionException (io.cucumber.cucumberexpressions.CucumberExpressionException)1