Search in sources :

Example 1 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method throws_could_not_convert_exception_for_docstring.

@Test
void throws_could_not_convert_exception_for_docstring() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some cukes in my belly\n" + "       \"\"\"doc\n" + "        converting this should throw an exception\n" + "       \"\"\"\n");
    stepTypeRegistry.defineDocStringType(new DocStringType(ItemQuantity.class, "doc", content -> {
        throw new IllegalArgumentException(content);
    }));
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have some cukes in my belly", ItemQuantity.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(step);
    StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
    assertThat(actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have some cukes in my belly] defined at '{stubbed location with details}'.")));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Step(io.cucumber.core.gherkin.Step) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) DataTableType(io.cucumber.datatable.DataTableType) Located(io.cucumber.core.backend.Located) StepDefinition(io.cucumber.core.backend.StepDefinition) StepExpression(io.cucumber.core.stepexpression.StepExpression) Arrays.asList(java.util.Arrays.asList) Is.is(org.hamcrest.core.Is.is) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ENGLISH(java.util.Locale.ENGLISH) EventBus(io.cucumber.core.eventbus.EventBus) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StepTypeRegistry(io.cucumber.core.stepexpression.StepTypeRegistry) StepExpressionFactory(io.cucumber.core.stepexpression.StepExpressionFactory) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) InvocationTargetException(java.lang.reflect.InvocationTargetException) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Test(org.junit.jupiter.api.Test) List(java.util.List) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) Argument(io.cucumber.core.stepexpression.Argument) DocStringType(io.cucumber.docstring.DocStringType) Clock(java.time.Clock) Collections(java.util.Collections) CucumberException(io.cucumber.core.exception.CucumberException) ParameterType(io.cucumber.cucumberexpressions.ParameterType) Argument(io.cucumber.core.stepexpression.Argument) Step(io.cucumber.core.gherkin.Step) Feature(io.cucumber.core.gherkin.Feature) DocStringType(io.cucumber.docstring.DocStringType) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 2 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class TestNGFormatterTest method testScenarioWithPassedSteps.

@Test
void testScenarioWithPassedSteps() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step\n" + "    Then step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new TestNGFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("step"))).build().run();
    String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"1\" failed=\"0\" skipped=\"0\">" + "    <suite name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"0\">" + "        <test name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"0\">" + "            <class name=\"feature\">" + "                <test-method name=\"scenario\" status=\"PASS\" duration-ms=\"0\" started-at=\"1970-01-01T00:00:00Z\" finished-at=\"1970-01-01T00:00:00Z\"/>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>";
    assertXmlEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 3 with Feature

use of io.cucumber.core.gherkin.Feature 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 4 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class TestNGFormatterTest method testScenarioOutlineWithExamples.

@Test
void testScenarioOutlineWithExamples() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature\n" + "  Scenario Outline: scenario\n" + "    When step\n" + "    Then step\n" + "    Examples:\n" + "    | arg |\n" + "    |  1  |\n" + "    |  2  |\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new TestNGFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier()).build().run();
    String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testng-results failed=\"2\" passed=\"0\" skipped=\"0\" total=\"2\">\n" + "    <suite duration-ms=\"0\" name=\"io.cucumber.core.plugin.TestNGFormatter\">\n" + "        <test duration-ms=\"0\" name=\"io.cucumber.core.plugin.TestNGFormatter\">\n" + "            <class name=\"feature\">\n" + "                <test-method duration-ms=\"0\" finished-at=\"1970-01-01T00:00:00Z\" name=\"scenario\" started-at=\"1970-01-01T00:00:00Z\" status=\"FAIL\">\n" + "                    <exception class=\"The scenario has pending or undefined step(s)\">\n" + "                        <message>\n" + "                            <![CDATA[When step...................................................................undefined\n" + "Then step...................................................................skipped\n" + "]]>\n" + "                        </message>\n" + "                        <full-stacktrace>\n" + "                            <![CDATA[The scenario has pending or undefined step(s)]]>\n" + "                        </full-stacktrace>\n" + "                    </exception>\n" + "                </test-method>\n" + "                <test-method duration-ms=\"0\" finished-at=\"1970-01-01T00:00:00Z\" name=\"scenario_2\" started-at=\"1970-01-01T00:00:00Z\" status=\"FAIL\">\n" + "                    <exception class=\"The scenario has pending or undefined step(s)\">\n" + "                        <message>\n" + "                            <![CDATA[When step...................................................................undefined\n" + "Then step...................................................................skipped\n" + "]]>\n" + "                        </message>\n" + "                        <full-stacktrace>\n" + "                            <![CDATA[The scenario has pending or undefined step(s)]]>\n" + "                        </full-stacktrace>\n" + "                    </exception>\n" + "                </test-method>\n" + "            </class>\n" + "        </test>\n" + "    </suite>\n" + "</testng-results>\n";
    assertXmlEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 5 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class TestNGFormatterTest method testScenarioWithUndefinedSteps.

@Test
void testScenarioWithUndefinedSteps() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step\n" + "    Then step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new TestNGFormatter(out)).withEventBus(new TimeServiceEventBus(fixed(EPOCH, of("UTC")), UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier()).build().run();
    String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testng-results failed=\"1\" passed=\"0\" skipped=\"0\" total=\"1\">\n" + "    <suite duration-ms=\"0\" name=\"io.cucumber.core.plugin.TestNGFormatter\">\n" + "        <test duration-ms=\"0\" name=\"io.cucumber.core.plugin.TestNGFormatter\">\n" + "            <class name=\"feature\">\n" + "                <test-method duration-ms=\"0\" finished-at=\"1970-01-01T00:00:00Z\" name=\"scenario\" started-at=\"1970-01-01T00:00:00Z\" status=\"FAIL\">\n" + "                    <exception class=\"The scenario has pending or undefined step(s)\">\n" + "                        <message>\n" + "                            <![CDATA[When step...................................................................undefined\n" + "Then step...................................................................skipped\n" + "]]>\n" + "                        </message>\n" + "                        <full-stacktrace>\n" + "                            <![CDATA[The scenario has pending or undefined step(s)]]>\n" + "                        </full-stacktrace>\n" + "                    </exception>\n" + "                </test-method>\n" + "            </class>\n" + "        </test>\n" + "    </suite>\n" + "</testng-results>\n";
    assertXmlEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Aggregations

Feature (io.cucumber.core.gherkin.Feature)152 Test (org.junit.jupiter.api.Test)144 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)92 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)78 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)77 UUID (java.util.UUID)67 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)59 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)26 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)23 Step (io.cucumber.core.gherkin.Step)22 StepDefinition (io.cucumber.core.backend.StepDefinition)21 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)21 Argument (io.cucumber.core.stepexpression.Argument)18 StepExpression (io.cucumber.core.stepexpression.StepExpression)18 DocString (io.cucumber.docstring.DocString)17 Executable (org.junit.jupiter.api.function.Executable)16 URI (java.net.URI)15 Arrays.asList (java.util.Arrays.asList)14 Collections.singletonList (java.util.Collections.singletonList)13