Search in sources :

Example 1 with ClasspathResourceLoader

use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.

the class BackgroundTest method should_run_background.

@Test
public void should_run_background() throws IOException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    RuntimeOptions runtimeOptions = new RuntimeOptions("");
    Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(mock(Backend.class)), runtimeOptions);
    CucumberFeature feature = feature("test.feature", "" + "Feature:\n" + "  Background:\n" + "    Given b\n" + "  Scenario:\n" + "    When s\n");
    StringBuilder out = new StringBuilder();
    PrettyFormatter pretty = new PrettyFormatter(out, true, true);
    feature.run(pretty, pretty, runtime);
    String expectedOutput = "" + "Feature: \n" + "\n" + "  Background:  # test.feature:2\n" + "    Given b\n" + "\n" + "  Scenario:  # test.feature:4\n" + "    When s\n";
    assertEquals(expectedOutput, out.toString());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) PrettyFormatter(gherkin.formatter.PrettyFormatter) Test(org.junit.Test)

Example 2 with ClasspathResourceLoader

use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method runFeaturesWithJunitFormatter.

private File runFeaturesWithJunitFormatter(final List<String> featurePaths, boolean strict) throws IOException {
    File report = File.createTempFile("cucumber-jvm-junit", "xml");
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
    List<String> args = new ArrayList<String>();
    if (strict) {
        args.add("--strict");
    }
    args.add("--plugin");
    args.add("junit:" + report.getAbsolutePath());
    args.addAll(featurePaths);
    RuntimeOptions runtimeOptions = new RuntimeOptions(args);
    Backend backend = mock(Backend.class);
    when(backend.getSnippet(any(Step.class), any(FunctionNameGenerator.class))).thenReturn("TEST SNIPPET");
    final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, classLoader, asList(backend), runtimeOptions);
    runtime.run();
    return report;
}
Also used : ArrayList(java.util.ArrayList) Step(gherkin.formatter.model.Step) Backend(cucumber.runtime.Backend) Runtime(cucumber.runtime.Runtime) FunctionNameGenerator(cucumber.runtime.snippets.FunctionNameGenerator) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Runtime(cucumber.runtime.Runtime) File(java.io.File) RuntimeOptions(cucumber.runtime.RuntimeOptions)

Example 3 with ClasspathResourceLoader

use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.

the class ExecutionUnitRunnerTest method shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario.

@Test
public void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInAScenario() throws Exception {
    List<CucumberFeature> features = CucumberFeature.load(new ClasspathResourceLoader(this.getClass().getClassLoader()), asList("cucumber/runtime/junit/fb.feature"), Collections.emptyList());
    ExecutionUnitRunner runner = new ExecutionUnitRunner(null, (CucumberScenario) features.get(0).getFeatureElements().get(0), createStandardJUnitReporter());
    // fish out the two occurrences of the same step and check whether we really got them
    Step stepOccurrence1 = runner.getChildren().get(0);
    Step stepOccurrence2 = runner.getChildren().get(2);
    assertEquals(stepOccurrence1.getName(), stepOccurrence2.getName());
    // then check that the descriptions are unequal
    Description runnerDescription = runner.getDescription();
    Description stepDescription1 = runnerDescription.getChildren().get(0);
    Description stepDescription2 = runnerDescription.getChildren().get(2);
    assertFalse("Descriptions must not be equal.", stepDescription1.equals(stepDescription2));
}
Also used : Description(org.junit.runner.Description) CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Step(gherkin.formatter.model.Step) Test(org.junit.Test)

Example 4 with ClasspathResourceLoader

use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.

the class RuntimeTest method runs_feature_with_json_formatter.

@Ignore
@Test
public void runs_feature_with_json_formatter() throws Exception {
    CucumberFeature feature = feature("test.feature", "" + "Feature: feature name\n" + "  Background: background name\n" + "    Given b\n" + "  Scenario: scenario name\n" + "    When s\n");
    StringBuilder out = new StringBuilder();
    JSONFormatter jsonFormatter = new CucumberJSONFormatter(out);
    List<Backend> backends = asList(mock(Backend.class));
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    RuntimeOptions runtimeOptions = new RuntimeOptions("");
    Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, backends, runtimeOptions);
    feature.run(jsonFormatter, jsonFormatter, runtime);
    jsonFormatter.done();
    String expected = "" + "[\n" + "  {\n" + "    \"id\": \"feature-name\",\n" + "    \"description\": \"\",\n" + "    \"name\": \"feature name\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"line\": 1,\n" + "    \"elements\": [\n" + "      {\n" + "        \"description\": \"\",\n" + "        \"name\": \"background name\",\n" + "        \"keyword\": \"Background\",\n" + "        \"line\": 2,\n" + "        \"steps\": [\n" + "          {\n" + "            \"result\": {\n" + "              \"status\": \"undefined\"\n" + "            },\n" + "            \"name\": \"b\",\n" + "            \"keyword\": \"Given \",\n" + "            \"line\": 3,\n" + "            \"match\": {}\n" + "          }\n" + "        ],\n" + "        \"type\": \"background\"\n" + "      },\n" + "      {\n" + "        \"id\": \"feature-name;scenario-name\",\n" + "        \"description\": \"\",\n" + "        \"name\": \"scenario name\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"line\": 4,\n" + "        \"steps\": [\n" + "          {\n" + "            \"result\": {\n" + "              \"status\": \"undefined\"\n" + "            },\n" + "            \"name\": \"s\",\n" + "            \"keyword\": \"When \",\n" + "            \"line\": 5,\n" + "            \"match\": {}\n" + "          }\n" + "        ],\n" + "        \"type\": \"scenario\"\n" + "      }\n" + "    ],\n" + "    \"uri\": \"test.feature\"\n" + "  }\n" + "]";
    assertEquals(expected, out.toString());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) JSONFormatter(gherkin.formatter.JSONFormatter) CucumberJSONFormatter(cucumber.runtime.formatter.CucumberJSONFormatter) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) CucumberJSONFormatter(cucumber.runtime.formatter.CucumberJSONFormatter) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with ClasspathResourceLoader

use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.

the class RuntimeTest method should_throw_cucumer_exception_if_no_backends_are_found.

@Test
public void should_throw_cucumer_exception_if_no_backends_are_found() throws Exception {
    try {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        new Runtime(new ClasspathResourceLoader(classLoader), classLoader, Collections.<Backend>emptyList(), new RuntimeOptions(""));
        fail("A CucumberException should have been thrown");
    } catch (CucumberException e) {
        assertEquals("No backends were found. Please make sure you have a backend module on your CLASSPATH.", e.getMessage());
    }
}
Also used : ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Test(org.junit.Test)

Aggregations

ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)10 CucumberFeature (cucumber.runtime.model.CucumberFeature)6 Test (org.junit.Test)6 Step (gherkin.formatter.model.Step)4 Runtime (cucumber.runtime.Runtime)3 RuntimeOptions (cucumber.runtime.RuntimeOptions)3 Backend (cucumber.runtime.Backend)2 StopWatch (cucumber.runtime.StopWatch)2 FunctionNameGenerator (cucumber.runtime.snippets.FunctionNameGenerator)2 Tag (gherkin.formatter.model.Tag)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Description (org.junit.runner.Description)2 HookDefinition (cucumber.runtime.HookDefinition)1 RuntimeGlue (cucumber.runtime.RuntimeGlue)1 CucumberJSONFormatter (cucumber.runtime.formatter.CucumberJSONFormatter)1 CucumberScenario (cucumber.runtime.model.CucumberScenario)1 Formatter (gherkin.formatter.Formatter)1 JSONFormatter (gherkin.formatter.JSONFormatter)1 PrettyFormatter (gherkin.formatter.PrettyFormatter)1