Search in sources :

Example 1 with ResourceLoaderClassFinder

use of cucumber.runtime.io.ResourceLoaderClassFinder in project intellij-community by JetBrains.

the class CucumberMain method run.

public static int run(final String[] argv, final ClassLoader classLoader) throws IOException {
    final Ref<Throwable> errorRef = new Ref<>();
    final Ref<Runtime> runtimeRef = new Ref<>();
    try {
        TestRunnerUtil.replaceIdeEventQueueSafely();
        UIUtil.invokeAndWaitIfNeeded(new Runnable() {

            @Override
            public void run() {
                try {
                    RuntimeOptions runtimeOptions = new RuntimeOptions(new ArrayList(Arrays.asList(argv)));
                    MultiLoader resourceLoader = new MultiLoader(classLoader);
                    ResourceLoaderClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
                    Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
                    runtimeRef.set(runtime);
                    runtime.run();
                } catch (Throwable throwable) {
                    errorRef.set(throwable);
                    Logger.getInstance(CucumberMain.class).error(throwable);
                }
            }
        });
    } catch (Throwable t) {
        errorRef.set(t);
        Logger.getInstance(CucumberMain.class).error(t);
    }
    final Throwable throwable = errorRef.get();
    if (throwable != null) {
        throwable.printStackTrace();
    }
    System.err.println("Failed tests :");
    for (Throwable error : runtimeRef.get().getErrors()) {
        error.printStackTrace();
        System.err.println("=============================");
    }
    return throwable != null ? 1 : 0;
}
Also used : ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) Ref(com.intellij.openapi.util.Ref) Runtime(cucumber.runtime.Runtime) MultiLoader(cucumber.runtime.io.MultiLoader) ArrayList(java.util.ArrayList) RuntimeOptions(cucumber.runtime.RuntimeOptions)

Example 2 with ResourceLoaderClassFinder

use of cucumber.runtime.io.ResourceLoaderClassFinder in project cucumber-jvm by cucumber.

the class Main method run.

/**
     * 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();
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) Runtime(cucumber.runtime.Runtime) MultiLoader(cucumber.runtime.io.MultiLoader) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) ClassFinder(cucumber.runtime.ClassFinder) RuntimeOptions(cucumber.runtime.RuntimeOptions)

Example 3 with ResourceLoaderClassFinder

use of cucumber.runtime.io.ResourceLoaderClassFinder in project cucumber-jvm by cucumber.

the class MethodScannerTest method loadGlue_registers_the_methods_declaring_class_in_the_object_factory.

@Test
public void loadGlue_registers_the_methods_declaring_class_in_the_object_factory() throws NoSuchMethodException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    ResourceLoader resourceLoader = new MultiLoader(classLoader);
    MethodScanner methodScanner = new MethodScanner(new ResourceLoaderClassFinder(resourceLoader, classLoader));
    ObjectFactory factory = Mockito.mock(ObjectFactory.class);
    Glue world = Mockito.mock(Glue.class);
    JavaBackend backend = new JavaBackend(factory);
    Whitebox.setInternalState(backend, "glue", world);
    // this delegates to methodScanner.scan which we test
    methodScanner.scan(backend, BaseStepDefs.class.getMethod("m"), BaseStepDefs.class);
    verify(factory, times(1)).addClass(BaseStepDefs.class);
    verifyNoMoreInteractions(factory);
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) ObjectFactory(cucumber.api.java.ObjectFactory) Glue(cucumber.runtime.Glue) MultiLoader(cucumber.runtime.io.MultiLoader) Test(org.junit.Test)

Aggregations

MultiLoader (cucumber.runtime.io.MultiLoader)3 ResourceLoaderClassFinder (cucumber.runtime.io.ResourceLoaderClassFinder)3 Runtime (cucumber.runtime.Runtime)2 RuntimeOptions (cucumber.runtime.RuntimeOptions)2 ResourceLoader (cucumber.runtime.io.ResourceLoader)2 Ref (com.intellij.openapi.util.Ref)1 ObjectFactory (cucumber.api.java.ObjectFactory)1 ClassFinder (cucumber.runtime.ClassFinder)1 Glue (cucumber.runtime.Glue)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1