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;
  }
 private void printSummary() {
   for (Throwable t : runtime.getErrors()) {
     Log.e(TAG, t.toString());
   }
   for (String s : runtime.getSnippets()) {
     Log.w(TAG, s);
   }
 }
Example #3
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();
  }
 @Before
 public void buildMockWorld() {
   ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
   RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties());
   runtime =
       new Runtime(
           mock(ResourceLoader.class), classLoader, asList(mock(Backend.class)), runtimeOptions);
   runtime.buildBackendWorlds(null);
   glue = runtime.getGlue();
 }
  @Test
  public void hooks_order_across_many_backends() throws Throwable {
    List<HookDefinition> backend1Hooks = mockHooks(3, Integer.MAX_VALUE, 1);
    for (HookDefinition hook : backend1Hooks) {
      glue.addBeforeHook(hook);
    }
    List<HookDefinition> backend2Hooks = mockHooks(2, Integer.MAX_VALUE, 4);
    for (HookDefinition hook : backend2Hooks) {
      glue.addBeforeHook(hook);
    }

    runtime.runBeforeHooks(mock(Reporter.class), new HashSet<Tag>());

    List<HookDefinition> allHooks = new ArrayList<HookDefinition>();
    allHooks.addAll(backend1Hooks);
    allHooks.addAll(backend2Hooks);

    InOrder inOrder = inOrder(allHooks.toArray());
    inOrder.verify(backend1Hooks.get(2)).execute(Matchers.<Scenario>any());
    inOrder.verify(backend2Hooks.get(0)).execute(Matchers.<Scenario>any());
    inOrder.verify(backend1Hooks.get(0)).execute(Matchers.<Scenario>any());
    inOrder.verify(backend2Hooks.get(2)).execute(Matchers.<Scenario>any());
    verify(backend2Hooks.get(1)).execute(Matchers.<Scenario>any());
    verify(backend1Hooks.get(1)).execute(Matchers.<Scenario>any());
  }
  @Test
  public void after_hooks_execute_in_reverse_order() throws Throwable {
    List<HookDefinition> hooks = mockHooks(2, Integer.MAX_VALUE, 4);
    for (HookDefinition hook : hooks) {
      glue.addAfterHook(hook);
    }

    runtime.runAfterHooks(mock(Reporter.class), new HashSet<Tag>());

    InOrder inOrder = inOrder(hooks.toArray());
    inOrder.verify(hooks.get(1)).execute(Matchers.<Scenario>any());
    inOrder.verify(hooks.get(2)).execute(Matchers.<Scenario>any());
    inOrder.verify(hooks.get(0)).execute(Matchers.<Scenario>any());
  }