Search in sources :

Example 1 with ClassFinder

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

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

use of cucumber.runtime.ClassFinder in project activityinfo by bedatadriven.

the class ScenarioTestCase method createCucumberRuntime.

private Runtime createCucumberRuntime() {
    List<Module> moduleList = new ArrayList<>();
    moduleList.add(new ScenarioModule(new SequentialScenarioScope()));
    moduleList.addAll(testConditions.getModules());
    Injector injector = Guice.createInjector(moduleList);
    ClassLoader classLoader = getClass().getClassLoader();
    ResourceLoader resourceLoader = new MultiLoader(classLoader);
    ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    JavaBackend backend = new JavaBackend(new GuiceObjectFactory(injector), classFinder);
    return new Runtime(resourceLoader, classLoader, Collections.singleton(backend), options);
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) JavaBackend(cucumber.runtime.java.JavaBackend) MultiLoader(cucumber.runtime.io.MultiLoader) ScenarioModule(cucumber.runtime.java.guice.impl.ScenarioModule) ArrayList(java.util.ArrayList) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) Runtime(cucumber.runtime.Runtime) Injector(com.google.inject.Injector) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) ClassFinder(cucumber.runtime.ClassFinder) SequentialScenarioScope(cucumber.runtime.java.guice.impl.SequentialScenarioScope) Module(com.google.inject.Module) ScenarioModule(cucumber.runtime.java.guice.impl.ScenarioModule)

Example 4 with ClassFinder

use of cucumber.runtime.ClassFinder in project activityinfo by bedatadriven.

the class TestMain method queueTestMethods.

private void queueTestMethods(String environment, Module... driverModules) {
    List<Module> modules = new ArrayList<>();
    modules.add(new SystemUnderTest(url));
    modules.add(new EmailModule());
    modules.addAll(Arrays.asList(driverModules));
    TestConditions conditions = new TestConditions(environment, modules);
    Predicate<String> filter = filterPredicate();
    ClassLoader classLoader = getClass().getClassLoader();
    ClassFinder classFinder = new ResourceLoaderClassFinder(new MultiLoader(classLoader), classLoader);
    Collection<Class<?>> testClasses = classFinder.getDescendants(Object.class, "org.activityinfo.test.ui");
    for (Class<?> testClass : testClasses) {
        for (Method method : JUnitUiTestCase.findTestMethods(testClass)) {
            if (filter.apply(method.getName()) || filter.apply(method.getDeclaringClass().getName())) {
                queueTestCase(new JUnitUiTestCase(method, conditions));
            }
        }
    }
}
Also used : MultiLoader(cucumber.runtime.io.MultiLoader) Method(java.lang.reflect.Method) EmailModule(org.activityinfo.test.driver.mail.EmailModule) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) SystemUnderTest(org.activityinfo.test.sut.SystemUnderTest) ResourceLoaderClassFinder(cucumber.runtime.io.ResourceLoaderClassFinder) ClassFinder(cucumber.runtime.ClassFinder) OdkModule(org.activityinfo.test.webdriver.OdkModule) Module(com.google.inject.Module) ApiModule(org.activityinfo.test.driver.ApiModule) WebDriverModule(org.activityinfo.test.webdriver.WebDriverModule) EmailModule(org.activityinfo.test.driver.mail.EmailModule)

Aggregations

ClassFinder (cucumber.runtime.ClassFinder)4 Runtime (cucumber.runtime.Runtime)3 MultiLoader (cucumber.runtime.io.MultiLoader)3 ResourceLoader (cucumber.runtime.io.ResourceLoader)3 ResourceLoaderClassFinder (cucumber.runtime.io.ResourceLoaderClassFinder)3 Module (com.google.inject.Module)2 RuntimeOptions (cucumber.runtime.RuntimeOptions)2 JavaBackend (cucumber.runtime.java.JavaBackend)2 Injector (com.google.inject.Injector)1 ObjectFactory (cucumber.api.java.ObjectFactory)1 OsgiClassFinder (cucumber.java.runtime.osgi.OsgiClassFinder)1 PaxExamObjectFactory (cucumber.java.runtime.osgi.PaxExamObjectFactory)1 Backend (cucumber.runtime.Backend)1 CucumberException (cucumber.runtime.CucumberException)1 RuntimeOptionsFactory (cucumber.runtime.RuntimeOptionsFactory)1 FileResourceLoader (cucumber.runtime.io.FileResourceLoader)1 ScenarioModule (cucumber.runtime.java.guice.impl.ScenarioModule)1 SequentialScenarioScope (cucumber.runtime.java.guice.impl.SequentialScenarioScope)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1