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("--format");
    args.add("json:" + report.getAbsolutePath());
    args.addAll(featurePaths);

    RuntimeOptions runtimeOptions =
        new RuntimeOptions(new Properties(), args.toArray(new String[args.size()]));
    Backend backend = mock(Backend.class);
    when(backend.getSnippet(any(Step.class), any(FunctionNameSanitizer.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;
  }
Example #2
0
  /**
   * Launches the Cucumber-JVM command line.
   *
   * @param argv runtime options. See details in the {@code cucumber.api.cli.Usage.txt} resource.
   * @param classLoader classloader used to load the runtime
   * @return 0 if execution was successful, 1 if it was not (test failures)
   * @throws IOException if resources couldn't be loaded during the run.
   */
  public static byte run(String[] argv, ClassLoader classLoader) throws IOException {
    RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList<String>(asList(argv)));

    ResourceLoader resourceLoader = new MultiLoader(classLoader);
    ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
    runtime.run();
    return runtime.exitStatus();
  }