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());
}
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;
}
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));
}
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());
}
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());
}
}
Aggregations