Search in sources :

Example 16 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class Java8StepDefinitionTest method should_pass_for_param_with_generic_list.

@Test
public void should_pass_for_param_with_generic_list() throws Exception {
    try {
        StepdefBody body = (StepdefBody.A1<List<String>>) p1 -> {
        };
        new Java8StepDefinition(Pattern.compile("^I have (\\d) some step (.*)$"), 0, body, typeIntrospector);
    } catch (CucumberException expected) {
        assertEquals("Can't use java.util.List in lambda step definition. Declare a DataTable argument instead and convert manually with asList/asLists/asMap/asMaps", expected.getMessage());
    }
}
Also used : Java8StepDefinition(cucumber.runtime.java.Java8StepDefinition) CucumberException(cucumber.runtime.CucumberException) StepdefBody(cucumber.api.java8.StepdefBody) Test(org.junit.Test)

Example 17 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class Java8StepDefinitionTest method should_fail_for_param_with_non_generic_list.

@Test
public void should_fail_for_param_with_non_generic_list() throws Exception {
    try {
        StepdefBody body = (StepdefBody.A1<List>) p1 -> {
        };
        new Java8StepDefinition(Pattern.compile("^I have (\\d) some step (.*)$"), 0, body, typeIntrospector);
    } catch (CucumberException expected) {
        assertEquals("Can't use java.util.List in lambda step definition. Declare a DataTable argument instead and convert manually with asList/asLists/asMap/asMaps", expected.getMessage());
    }
}
Also used : Java8StepDefinition(cucumber.runtime.java.Java8StepDefinition) CucumberException(cucumber.runtime.CucumberException) StepdefBody(cucumber.api.java8.StepdefBody) Test(org.junit.Test)

Example 18 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class CucumberTest method testThatFileIsNotCreatedOnParsingError.

@Test
public void testThatFileIsNotCreatedOnParsingError() throws Exception {
    try {
        new Cucumber(FormatterWithLexerErrorFeature.class);
        fail("Expecting error");
    } catch (CucumberException e) {
        assertFalse("File is created despite Lexor Error", new File("lexor_error_feature.json").exists());
    }
}
Also used : CucumberException(cucumber.runtime.CucumberException) Cucumber(cucumber.api.junit.Cucumber) File(java.io.File) Test(org.junit.Test)

Example 19 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class JUnitReporterTest method throws_exception_when_runner_step_name_do_no_match_scenario_step_name.

@Test
public void throws_exception_when_runner_step_name_do_no_match_scenario_step_name() throws Exception {
    Step runnerStep = mockStep("Runner Step Name");
    ExecutionUnitRunner executionUnitRunner = mockExecutionUnitRunner(runnerSteps(runnerStep));
    jUnitReporter = new JUnitReporter(mock(Reporter.class), mock(Formatter.class), false, new JUnitOptions(Collections.<String>emptyList()));
    jUnitReporter.startExecutionUnit(executionUnitRunner, mock(RunNotifier.class));
    jUnitReporter.startOfScenarioLifeCycle(mock(Scenario.class));
    jUnitReporter.step(mockStep("Scenario Step Name"));
    try {
        jUnitReporter.match(mock(Match.class));
        fail("CucumberException not thrown");
    } catch (CucumberException e) {
        assertEquals("Expected step: \"Scenario Step Name\" got step: \"Runner Step Name\"", e.getMessage());
    } catch (Exception e) {
        fail("CucumberException not thrown");
    }
}
Also used : RunNotifier(org.junit.runner.notification.RunNotifier) Step(gherkin.formatter.model.Step) CucumberException(cucumber.runtime.CucumberException) PendingException(cucumber.api.PendingException) CucumberException(cucumber.runtime.CucumberException) Scenario(gherkin.formatter.model.Scenario) Match(gherkin.formatter.model.Match) Test(org.junit.Test)

Example 20 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class FeatureRunner method buildFeatureElementRunners.

private void buildFeatureElementRunners() {
    for (CucumberTagStatement cucumberTagStatement : cucumberFeature.getFeatureElements()) {
        try {
            ParentRunner featureElementRunner;
            if (cucumberTagStatement instanceof CucumberScenario) {
                featureElementRunner = new ExecutionUnitRunner(runtime, (CucumberScenario) cucumberTagStatement, jUnitReporter);
            } else {
                featureElementRunner = new ScenarioOutlineRunner(runtime, (CucumberScenarioOutline) cucumberTagStatement, jUnitReporter);
            }
            children.add(featureElementRunner);
        } catch (InitializationError e) {
            throw new CucumberException("Failed to create scenario runner", e);
        }
    }
}
Also used : CucumberScenarioOutline(cucumber.runtime.model.CucumberScenarioOutline) InitializationError(org.junit.runners.model.InitializationError) CucumberScenario(cucumber.runtime.model.CucumberScenario) CucumberTagStatement(cucumber.runtime.model.CucumberTagStatement) CucumberException(cucumber.runtime.CucumberException) ParentRunner(org.junit.runners.ParentRunner)

Aggregations

CucumberException (cucumber.runtime.CucumberException)37 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 SingleValueConverter (cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter)4 IOException (java.io.IOException)4 Step (gherkin.formatter.model.Step)3 ObjectFactory (cucumber.api.java.ObjectFactory)2 StepdefBody (cucumber.api.java8.StepdefBody)2 RuntimeOptionsFactory (cucumber.runtime.RuntimeOptionsFactory)2 Resource (cucumber.runtime.io.Resource)2 Java8StepDefinition (cucumber.runtime.java.Java8StepDefinition)2 AssetManager (android.content.res.AssetManager)1 DataTable (cucumber.api.DataTable)1 PendingException (cucumber.api.PendingException)1 Scenario (cucumber.api.Scenario)1 After (cucumber.api.java.After)1 Cucumber (cucumber.api.junit.Cucumber)1 OsgiClassFinder (cucumber.java.runtime.osgi.OsgiClassFinder)1 PaxExamObjectFactory (cucumber.java.runtime.osgi.PaxExamObjectFactory)1 Backend (cucumber.runtime.Backend)1