Search in sources :

Example 6 with Feature

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

the class TestNGFormatterTest method testScenarioWithBackground.

@Test
void testScenarioWithBackground() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature\n" + "  Background:\n" + "    When background\n" + "    Then background\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 background.............................................................undefined\n" + "Then background.............................................................skipped\n" + "When step...................................................................skipped\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 7 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_singleton_table_dimension_mismatch.

@Test
void throws_could_not_convert_exception_for_singleton_table_dimension_mismatch() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some cukes in my belly\n" + "       | 3 | \n" + "       | 14 | \n" + "       | 15 | \n");
    stepTypeRegistry.defineDataTableType(new DataTableType(ItemQuantity.class, ItemQuantity::new));
    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 : DataTableType(io.cucumber.datatable.DataTableType) Argument(io.cucumber.core.stepexpression.Argument) Step(io.cucumber.core.gherkin.Step) Feature(io.cucumber.core.gherkin.Feature) 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 8 with Feature

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

the class TestNGFormatterTest method testDurationCalculationOfStepsAndHooks.

@Test
void testDurationCalculationOfStepsAndHooks() {
    Feature feature1 = TestFeatureParser.parse("path/feature1.feature", "" + "Feature: feature_1\n" + "  Scenario: scenario_1\n" + "    When step\n" + "    Then step\n" + "  Scenario: scenario_2\n" + "    When step\n" + "    Then step\n");
    Feature feature2 = TestFeatureParser.parse("path/feature2.feature", "" + "Feature: feature_2\n" + "  Scenario: scenario_3\n" + "    When step\n" + "    Then step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(() -> Arrays.asList(feature1, feature2)).withAdditionalPlugins(timeService, new TestNGFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition()), singletonList(new StubStepDefinition("step")), singletonList(new StubHookDefinition()))).build().run();
    String expected = "" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"3\" passed=\"3\" failed=\"0\" skipped=\"0\">" + "    <suite name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"12\">" + "        <test name=\"io.cucumber.core.plugin.TestNGFormatter\" duration-ms=\"12\">" + "            <class name=\"feature_1\">" + "                <test-method name=\"scenario_1\" status=\"PASS\" duration-ms=\"4\" started-at=\"1970-01-01T00:00:00Z\" finished-at=\"1970-01-01T00:00:00.004Z\"/>" + "                <test-method name=\"scenario_2\" status=\"PASS\" duration-ms=\"4\" started-at=\"1970-01-01T00:00:00.004Z\" finished-at=\"1970-01-01T00:00:00.008Z\"/>" + "            </class>" + "            <class name=\"feature_2\">" + "                <test-method name=\"scenario_3\" status=\"PASS\" duration-ms=\"4\" started-at=\"1970-01-01T00:00:00.008Z\" finished-at=\"1970-01-01T00:00:00.012Z\"/>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>";
    assertXmlEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 9 with Feature

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

the class TestNGFormatterTest method testScenarioWithPendingSteps.

@Test
void testScenarioWithPendingSteps() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step1\n" + "    Then step2\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("step1", new StubPendingException()), new StubStepDefinition("step2"))).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 step1..................................................................pending\n" + "Then step2..................................................................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) StubPendingException(io.cucumber.core.backend.StubPendingException) 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 10 with Feature

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

the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments.

@Test
void throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n");
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have {int} cukes in my belly");
    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("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Step [I have {int} cukes in my belly] is defined with 0 parameters at '{stubbed location with details}'.\n" + "However, the gherkin step has 1 arguments:\n" + " * 4\n" + "Step text: I have 4 cukes in my belly")));
}
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) 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) StepExpression(io.cucumber.core.stepexpression.StepExpression) 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