Search in sources :

Example 1 with Runtime

use of cucumber.runtime.Runtime in project cucumber-jvm by cucumber.

the class CalculatorTest method cucumber.

@Test
public void cucumber() throws Exception {
    assertNotNull(injector);
    assertNotNull(bundleContext);
    final ResourceLoader resourceLoader = new FileResourceLoader();
    final ClassLoader classLoader = Runtime.class.getClassLoader();
    final ObjectFactory objectFactory = new PaxExamObjectFactory(injector);
    final ClassFinder classFinder = new OsgiClassFinder(bundleContext);
    final Backend backend = new JavaBackend(objectFactory, classFinder);
    final RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(getClass());
    final RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
    final Runtime runtime = new Runtime(resourceLoader, classLoader, Collections.singleton(backend), runtimeOptions);
    runtime.run();
    if (!runtime.getErrors().isEmpty()) {
        throw new CucumberException(runtime.getErrors().get(0));
    } else if (runtime.exitStatus() != 0x00) {
        throw new CucumberException("There are pending or undefined steps.");
    }
    assertEquals(runtime.getErrors().size(), 0);
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) FileResourceLoader(cucumber.runtime.io.FileResourceLoader) JavaBackend(cucumber.runtime.java.JavaBackend) OsgiClassFinder(cucumber.java.runtime.osgi.OsgiClassFinder) Backend(cucumber.runtime.Backend) JavaBackend(cucumber.runtime.java.JavaBackend) Runtime(cucumber.runtime.Runtime) ObjectFactory(cucumber.api.java.ObjectFactory) PaxExamObjectFactory(cucumber.java.runtime.osgi.PaxExamObjectFactory) FileResourceLoader(cucumber.runtime.io.FileResourceLoader) PaxExamObjectFactory(cucumber.java.runtime.osgi.PaxExamObjectFactory) ClassFinder(cucumber.runtime.ClassFinder) OsgiClassFinder(cucumber.java.runtime.osgi.OsgiClassFinder) CucumberException(cucumber.runtime.CucumberException) RuntimeOptionsFactory(cucumber.runtime.RuntimeOptionsFactory) RuntimeOptions(cucumber.runtime.RuntimeOptions) Test(org.junit.Test)

Example 2 with Runtime

use of cucumber.runtime.Runtime in project cucumber-jvm by cucumber.

the class JUnitFormatterTest method runFeaturesWithJunitFormatter.

private File runFeaturesWithJunitFormatter(final List<String> featurePaths, boolean strict) throws IOException {
    File report = File.createTempFile("cucumber-jvm-junit", "xml");
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
    List<String> args = new ArrayList<String>();
    if (strict) {
        args.add("--strict");
    }
    args.add("--plugin");
    args.add("junit:" + 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 cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, classLoader, asList(backend), runtimeOptions);
    runtime.run();
    return report;
}
Also used : ArrayList(java.util.ArrayList) Step(gherkin.formatter.model.Step) Backend(cucumber.runtime.Backend) Runtime(cucumber.runtime.Runtime) FunctionNameGenerator(cucumber.runtime.snippets.FunctionNameGenerator) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) Runtime(cucumber.runtime.Runtime) File(java.io.File) RuntimeOptions(cucumber.runtime.RuntimeOptions)

Example 3 with Runtime

use of cucumber.runtime.Runtime 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 4 with Runtime

use of cucumber.runtime.Runtime 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 5 with Runtime

use of cucumber.runtime.Runtime 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)

Aggregations

Runtime (cucumber.runtime.Runtime)8 RuntimeOptions (cucumber.runtime.RuntimeOptions)6 ArrayList (java.util.ArrayList)4 Backend (cucumber.runtime.Backend)3 ClassFinder (cucumber.runtime.ClassFinder)3 ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)3 MultiLoader (cucumber.runtime.io.MultiLoader)3 ResourceLoader (cucumber.runtime.io.ResourceLoader)3 ResourceLoaderClassFinder (cucumber.runtime.io.ResourceLoaderClassFinder)3 StopWatch (cucumber.runtime.StopWatch)2 JavaBackend (cucumber.runtime.java.JavaBackend)2 FunctionNameGenerator (cucumber.runtime.snippets.FunctionNameGenerator)2 Step (gherkin.formatter.model.Step)2 File (java.io.File)2 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 Ref (com.intellij.openapi.util.Ref)1 ObjectFactory (cucumber.api.java.ObjectFactory)1 OsgiClassFinder (cucumber.java.runtime.osgi.OsgiClassFinder)1 PaxExamObjectFactory (cucumber.java.runtime.osgi.PaxExamObjectFactory)1