use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.
the class HookTest method after_hooks_execute_before_objects_are_disposed.
/**
* Test for <a href="https://github.com/cucumber/cucumber-jvm/issues/23">#23</a>.
* TODO: ensure this is no longer needed with the alternate approach taken in Runtime
* TODO: this test is rather brittle, since there's lots of mocking :(
*/
@Test
public void after_hooks_execute_before_objects_are_disposed() throws Throwable {
Backend backend = mock(Backend.class);
HookDefinition hook = mock(HookDefinition.class);
when(hook.matches(anyListOf(Tag.class))).thenReturn(true);
gherkin.formatter.model.Scenario gherkinScenario = mock(gherkin.formatter.model.Scenario.class);
CucumberFeature feature = mock(CucumberFeature.class);
Feature gherkinFeature = mock(Feature.class);
when(feature.getGherkinFeature()).thenReturn(gherkinFeature);
when(gherkinFeature.getTags()).thenReturn(new ArrayList<Tag>());
CucumberScenario scenario = new CucumberScenario(feature, null, gherkinScenario);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions("");
Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
runtime.getGlue().addAfterHook(hook);
scenario.run(mock(Formatter.class), mock(Reporter.class), runtime);
InOrder inOrder = inOrder(hook, backend);
inOrder.verify(hook).execute(Matchers.<Scenario>any());
inOrder.verify(backend).disposeWorld();
}
use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.
the class ExecutionUnitRunnerTest method shouldIncludeScenarioNameAsClassNameInStepDescriptions.
@Test
public void shouldIncludeScenarioNameAsClassNameInStepDescriptions() throws Exception {
List<CucumberFeature> features = CucumberFeature.load(new ClasspathResourceLoader(this.getClass().getClassLoader()), asList("cucumber/runtime/junit/feature_with_same_steps_in_different_scenarios.feature"), Collections.emptyList());
ExecutionUnitRunner runner = new ExecutionUnitRunner(null, (CucumberScenario) features.get(0).getFeatureElements().get(0), createStandardJUnitReporter());
// fish out the data from runner
Step step = runner.getChildren().get(0);
Description runnerDescription = runner.getDescription();
Description stepDescription = runnerDescription.getChildren().get(0);
assertEquals("description includes scenario name as class name", runner.getName(), stepDescription.getClassName());
assertEquals("description includes step keyword and name as method name", step.getKeyword() + step.getName(), stepDescription.getMethodName());
}
use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.
the class FeatureRunnerTest method runFeatureWithFormatterSpy.
private String runFeatureWithFormatterSpy(CucumberFeature cucumberFeature) throws InitializationError {
final RuntimeOptions runtimeOptions = new RuntimeOptions("");
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
final RuntimeGlue glue = mock(RuntimeGlue.class);
final Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions, new StopWatch.Stub(0l), glue);
FormatterSpy formatterSpy = new FormatterSpy();
FeatureRunner runner = new FeatureRunner(cucumberFeature, runtime, new JUnitReporter(formatterSpy, formatterSpy, false, new JUnitOptions(Collections.<String>emptyList())));
runner.run(mock(RunNotifier.class));
return formatterSpy.toString();
}
use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.
the class JSONPrettyFormatterTest method runFeaturesWithJSONPrettyFormatter.
private File runFeaturesWithJSONPrettyFormatter(final List<String> featurePaths) throws IOException {
HookDefinition hook = mock(HookDefinition.class);
when(hook.matches(anyListOf(Tag.class))).thenReturn(true);
File report = File.createTempFile("cucumber-jvm-junit", ".json");
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
List<String> args = new ArrayList<String>();
args.add("--plugin");
args.add("json:" + 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 Runtime runtime = new Runtime(resourceLoader, classLoader, asList(backend), runtimeOptions, new StopWatch.Stub(1234), null);
runtime.getGlue().addBeforeHook(hook);
runtime.run();
return report;
}
use of cucumber.runtime.io.ClasspathResourceLoader in project cucumber-jvm by cucumber.
the class TestHelper method runFeaturesWithFormatter.
private static void runFeaturesWithFormatter(final List<CucumberFeature> features, final Map<String, Result> stepsToResult, final Map<String, String> stepsToLocation, final List<SimpleEntry<String, Result>> hooks, final long stepHookDuration, final Formatter formatter, final Reporter reporter) throws Throwable {
final RuntimeOptions runtimeOptions = new RuntimeOptions("");
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
final RuntimeGlue glue = createMockedRuntimeGlueThatMatchesTheSteps(stepsToResult, stepsToLocation, hooks);
final Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions, new StopWatch.Stub(stepHookDuration), glue);
for (CucumberFeature feature : features) {
feature.run(formatter, reporter, runtime);
}
formatter.done();
formatter.close();
}
Aggregations