Search in sources :

Example 6 with ClasspathResourceLoader

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();
}
Also used : InOrder(org.mockito.InOrder) Formatter(gherkin.formatter.Formatter) Reporter(gherkin.formatter.Reporter) CucumberScenario(cucumber.runtime.model.CucumberScenario) CucumberFeature(cucumber.runtime.model.CucumberFeature) Feature(gherkin.formatter.model.Feature) CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Tag(gherkin.formatter.model.Tag) Test(org.junit.Test)

Example 7 with ClasspathResourceLoader

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());
}
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 8 with ClasspathResourceLoader

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();
}
Also used : Runtime(cucumber.runtime.Runtime) RunNotifier(org.junit.runner.notification.RunNotifier) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) RuntimeGlue(cucumber.runtime.RuntimeGlue) RuntimeOptions(cucumber.runtime.RuntimeOptions) StopWatch(cucumber.runtime.StopWatch)

Example 9 with ClasspathResourceLoader

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;
}
Also used : ArrayList(java.util.ArrayList) Step(gherkin.formatter.model.Step) StopWatch(cucumber.runtime.StopWatch) Backend(cucumber.runtime.Backend) Runtime(cucumber.runtime.Runtime) FunctionNameGenerator(cucumber.runtime.snippets.FunctionNameGenerator) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Tag(gherkin.formatter.model.Tag) File(java.io.File) RuntimeOptions(cucumber.runtime.RuntimeOptions) HookDefinition(cucumber.runtime.HookDefinition)

Example 10 with ClasspathResourceLoader

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();
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader)

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