Search in sources :

Example 1 with Result

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

the class Runtime method runStep.

public void runStep(String featurePath, Step step, Reporter reporter, I18n i18n) {
    StepDefinitionMatch match;
    try {
        match = glue.stepDefinitionMatch(featurePath, step, i18n);
    } catch (AmbiguousStepDefinitionsException e) {
        reporter.match(e.getMatches().get(0));
        Result result = new Result(Result.FAILED, 0L, e, DUMMY_ARG);
        reporter.result(result);
        addStepToCounterAndResult(result);
        addError(e);
        skipNextStep = true;
        return;
    }
    if (match != null) {
        reporter.match(match);
    } else {
        reporter.match(Match.UNDEFINED);
        reporter.result(Result.UNDEFINED);
        addStepToCounterAndResult(Result.UNDEFINED);
        skipNextStep = true;
        return;
    }
    if (runtimeOptions.isDryRun()) {
        skipNextStep = true;
    }
    if (skipNextStep) {
        addStepToCounterAndResult(Result.SKIPPED);
        reporter.result(Result.SKIPPED);
    } else {
        String status = Result.PASSED;
        Throwable error = null;
        stopWatch.start();
        try {
            match.runStep(i18n);
        } catch (Throwable t) {
            error = t;
            status = isPending(t) ? "pending" : Result.FAILED;
            addError(t);
            skipNextStep = true;
        } finally {
            long duration = stopWatch.stop();
            Result result = new Result(status, duration, error, DUMMY_ARG);
            addStepToCounterAndResult(result);
            reporter.result(result);
        }
    }
}
Also used : DocString(gherkin.formatter.model.DocString) Result(gherkin.formatter.model.Result)

Example 2 with Result

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

the class JUnitFormatterTest method should_format_scenario_outlines_with_multiple_examples.

@Test
public void should_format_scenario_outlines_with_multiple_examples() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "Feature: feature name\n" + "  Scenario Outline: outline name\n" + "    Given first step \"<arg>\"\n" + "    When second step\n" + "    Then third step\n\n" + "  Examples: examples 1\n" + "    | arg |\n" + "    |  a  |\n" + "    |  b  |\n\n" + "  Examples: examples 2\n" + "    | arg |\n" + "    |  c  |\n" + "    |  d  |\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("first step", result("passed"));
    stepsToResult.put("second step", result("passed"));
    stepsToResult.put("third step", result("passed"));
    long stepDuration = milliSeconds(1);
    String formatterOutput = runFeatureWithJUnitFormatter(feature, stepsToResult, stepDuration);
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<testsuite failures=\"0\" name=\"cucumber.runtime.formatter.JUnitFormatter\" skipped=\"0\" tests=\"4\" time=\"0.012\">\n" + "    <testcase classname=\"feature name\" name=\"outline name\" time=\"0.003\">\n" + "        <system-out><![CDATA[" + "Given first step \"a\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "    <testcase classname=\"feature name\" name=\"outline name 2\" time=\"0.003\">\n" + "        <system-out><![CDATA[" + "Given first step \"b\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "    <testcase classname=\"feature name\" name=\"outline name 3\" time=\"0.003\">\n" + "        <system-out><![CDATA[" + "Given first step \"c\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "    <testcase classname=\"feature name\" name=\"outline name 4\" time=\"0.003\">\n" + "        <system-out><![CDATA[" + "Given first step \"d\"........................................................passed\n" + "When second step............................................................passed\n" + "Then third step.............................................................passed\n" + "]]></system-out>\n" + "    </testcase>\n" + "</testsuite>\n";
    assertXmlEqual(expected, formatterOutput);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) HashMap(java.util.HashMap) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 3 with Result

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

the class TestNGFormatterTest method testScenarioWithBackground.

@Test
public void testScenarioWithBackground() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Background:\n" + "    When background\n" + "    Then background\n" + "  Scenario: scenario\n" + "    When step\n" + "    Then step\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("background", result("undefined"));
    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=\"1\" passed=\"0\" failed=\"0\" skipped=\"1\">" + "    <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\"/>" + "            </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 4 with Result

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

the class TestNGFormatterTest method testScenarioWithFailedSteps.

@Test
public void testScenarioWithFailedSteps() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step1\n" + "    Then step2\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step1", result("failed", new TestNGException("message", "stacktrace")));
    stepsToResult.put("step2", result("skipped"));
    long stepDuration = milliSeconds(0);
    String actual = runFeatureWithTestNGFormatter(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=\"cucumber.runtime.formatter.TestNGFormatterTest$TestNGException\">" + "                        <message><![CDATA[When step1..................................................................failed\n" + "Then step2..................................................................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) Result(gherkin.formatter.model.Result) Test(org.junit.Test)

Example 5 with Result

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

the class TestNGFormatterTest method testScenarioWithPendingSteps.

@Test
public final void testScenarioWithPendingSteps() throws Throwable {
    CucumberFeature feature = TestHelper.feature("path/test.feature", "" + "Feature: feature\n" + "  Scenario: scenario\n" + "    When step1\n" + "    Then step2\n");
    Map<String, Result> stepsToResult = new HashMap<String, Result>();
    stepsToResult.put("step1", result("pending"));
    stepsToResult.put("step2", result("skipped"));
    long stepDuration = milliSeconds(0);
    String actual = runFeatureWithTestNGFormatter(feature, stepsToResult, stepDuration);
    assertXmlEqual("" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<testng-results total=\"1\" passed=\"0\" failed=\"0\" skipped=\"1\">" + "    <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\"/>" + "            </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)

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