Search in sources :

Example 56 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class JavaStepDefinitionTest method throws_ambiguous_when_two_matches_are_found.

@Test
public void throws_ambiguous_when_two_matches_are_found() throws Throwable {
    backend.addStepDefinition(THREE_DISABLED_MICE.getAnnotation(Given.class), THREE_DISABLED_MICE);
    backend.addStepDefinition(THREE_BLIND_ANIMALS.getAnnotation(Given.class), THREE_BLIND_ANIMALS);
    Reporter reporter = mock(Reporter.class);
    runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), mock(Scenario.class));
    Tag tag = new Tag("@foo", 0);
    runtime.runBeforeHooks(reporter, asSet(tag));
    runtime.runStep("some.feature", new Step(NO_COMMENTS, "Given ", "three blind mice", 1, null, null), reporter, ENGLISH);
    ArgumentCaptor<Result> result = ArgumentCaptor.forClass(Result.class);
    verify(reporter).result(result.capture());
    assertEquals(AmbiguousStepDefinitionsException.class, result.getValue().getError().getClass());
}
Also used : Given(cucumber.api.java.en.Given) Reporter(gherkin.formatter.Reporter) Tag(gherkin.formatter.model.Tag) Step(gherkin.formatter.model.Step) Scenario(gherkin.formatter.model.Scenario) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 57 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class TestHelper method mockSteps.

private static void mockSteps(RuntimeGlue glue, Map<String, Result> stepsToResult, Map<String, String> stepsToLocation) throws Throwable {
    for (String stepName : mergeStepSets(stepsToResult, stepsToLocation)) {
        Result stepResult = getResultWithDefaultPassed(stepsToResult, stepName);
        if (!"undefined".equals(stepResult.getStatus())) {
            StepDefinitionMatch matchStep = mock(StepDefinitionMatch.class);
            when(glue.stepDefinitionMatch(anyString(), TestHelper.stepWithName(stepName), (I18n) any())).thenReturn(matchStep);
            mockStepResult(stepResult, matchStep);
            mockStepLocation(getLocationWithDefaultEmptyString(stepsToLocation, stepName), matchStep);
        }
    }
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) Result(gherkin.formatter.model.Result)

Example 58 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class TestNGFormatterTest method testScenarioWithUndefinedStepsStrict.

@Test
public void testScenarioWithUndefinedStepsStrict() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step\n" + "    Then step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step", result("undefined"));
    long stepDuration = milliSeconds(0);
    String actual = runFeatureWithStrictTestNGFormatter(feature, stepsToResult, stepDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\">" + "    <suite name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "        <test name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "            <class name=\"feature\">" + "                <test-method name=\"scenario\" status=\"FAIL\" duration-ms=\"0\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\">" + "                    <exception class=\"The scenario has pending or undefined step(s)\">" + "                        <message><![CDATA[When step...................................................................undefined\n" + "Then step...................................................................undefined\n" + "]]></message>" + "                        <full-stacktrace><![CDATA[The scenario has pending or undefined step(s)]]></full-stacktrace>" + "                    </exception>" + "                </test-method>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>", actual);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 59 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class TestNGFormatterTest method testScenarioOutlineWithExamples.

@Test
public void testScenarioOutlineWithExamples() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Scenario Outline: scenario\n" + "    When step\n" + "    Then step\n" + "    Examples:\n" + "    | arg |\n" + "    |  1  |\n" + "    |  2  |\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step", result("undefined"));
    long stepDuration = milliSeconds(0);
    String actual = runFeatureWithTestNGFormatter(feature, stepsToResult, stepDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"2\" passed=\"0\" failed=\"0\" skipped=\"2\">" + "    <suite name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "        <test name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "            <class name=\"feature\">" + "                <test-method name=\"scenario\" status=\"SKIP\" duration-ms=\"0\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\"/>" + "                <test-method name=\"scenario_2\" status=\"SKIP\" duration-ms=\"0\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\"/>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>", actual);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 60 with Result

use of gherkin.formatter.model.Result in project cucumber-jvm by cucumber.

the class TestNGFormatterTest method testScenarioWithFailedBeforeHook.

@Test
public void testScenarioWithFailedBeforeHook() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step\n" + "    Then step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step", result("skipped"));
    List<SimpleEntry<String, Result>> hooks = new ArrayList<SimpleEntry<String, Result>>();
    hooks.add(TestHelper.hookEntry("before", result("failed", new TestNGException("message", "stacktrace"))));
    long stepHookDuration = milliSeconds(0);
    String actual = runFeatureWithTestNGFormatter(feature, stepsToResult, hooks, stepHookDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\">" + "    <suite name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "        <test name=\"cucumber.runtime.formatter.TestNGFormatter\" duration-ms=\"0\">" + "            <class name=\"feature\">" + "                <test-method name=\"scenario\" status=\"FAIL\" duration-ms=\"0\" started-at=\"yyyy-MM-ddTHH:mm:ssZ\" finished-at=\"yyyy-MM-ddTHH:mm:ssZ\">" + "                    <exception class=\"cucumber.runtime.formatter.TestNGFormatterTest$TestNGException\">" + "                        <message><![CDATA[When step...................................................................skipped\n" + "Then step...................................................................skipped\n" + "]]></message>" + "                        <full-stacktrace><![CDATA[stacktrace]]></full-stacktrace>" + "                    </exception>" + "                </test-method>" + "            </class>" + "        </test>" + "    </suite>" + "</testng-results>", actual);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Aggregations

Result (gherkin.formatter.model.Result)75 Test (org.junit.Test)58 CucumberFeature (cucumber.runtime.model.CucumberFeature)32 HashMap (java.util.HashMap)32 Reporter (gherkin.formatter.Reporter)11 SimpleEntry (java.util.AbstractMap.SimpleEntry)10 ArrayList (java.util.ArrayList)10 Match (gherkin.formatter.model.Match)9 EachTestNotifier (org.junit.internal.runners.model.EachTestNotifier)8 Test (org.testng.annotations.Test)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintStream (java.io.PrintStream)6 PendingException (cucumber.api.PendingException)5 Matchers.anyString (org.mockito.Matchers.anyString)4 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)3 Scenario (gherkin.formatter.model.Scenario)3 List (java.util.List)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Given (cucumber.api.java.en.Given)2 DocString (gherkin.formatter.model.DocString)2