Cucumber-jvm and robolectric

258 views
Skip to first unread message

Marco

unread,
May 14, 2014, 4:52:07 AM5/14/14
to cu...@googlegroups.com
Hi people,
I'm working in a project for executing cucumber test with robolectric, so I writed a custom cucumber runner to execute also robolectric runner.
The robolectric class is executed by a custom class loader (AsmInstrumentingClassLoader), so I've tried to execute cucumber features with the same AsmInstrumentingClassLoader, but when I run tests, i get

cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
    at cucumber.runtime.Runtime.<init>(Runtime.java:77)
    at cucumber.runtime.Runtime.<init>(Runtime.java:66)
    at cucumber.runtime.Runtime.<init>(Runtime.java:62)
    at mytest.CustomCucumber.createRuntime(CustomCucumber.java:151)
    at mytest.CustomCucumber.loadFeatures(CustomCucumber.java:138)
    at mytest.CustomCucumber.<init>(CustomCucumber.java:121)
    at mytest.CucumberCustomTestRunner.<init>(CucumberCustomTestRunner.java:10)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


Someone have some hint?

CustomCucumber is essentially same as Cucumber class, with a custom constructor:

public CustomCucumber(Class classTest) throws InitializationError, IOException {
        super(classTest);
       
        EnvHolder envHolder;
        synchronized (envHoldersByTestRunner) {
            Class<? extends TestTest> testRunnerClass = classTest;
            envHolder = envHoldersByTestRunner.get(testRunnerClass);
            if (envHolder == null) {
                envHolder = new EnvHolder();
                envHoldersByTestRunner.put(testRunnerClass, envHolder);
            }
        }
        this.envHolder = envHolder;

        databaseMap = setupDatabaseMap(TestTest.class, new SQLiteMap());
               
        final Config config = getConfig();
        AndroidManifest appManifest = getAppManifest(config);
        SdkEnvironment sdkEnvironment = getEnvironment(appManifest, config);
       
        ClassLoader classLoader = sdkEnvironment.getRobolectricClassLoader();
        Assertions.assertNoCucumberAnnotatedMethods(classTest);
       

        RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(classTest, new Class[]{CucumberOptions.class, Options.class});
        RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();

        ResourceLoader resourceLoader = new MultiLoader(classLoader);
        runtime = createRuntime(resourceLoader, classLoader, runtimeOptions);

        final List<CucumberFeature> cucumberFeatures = runtimeOptions.cucumberFeatures(resourceLoader);
        jUnitReporter = new JUnitReporter(runtimeOptions.reporter(classLoader), runtimeOptions.formatter(classLoader), runtimeOptions.isStrict());
        addChildren(cucumberFeatures);      
    }


The core of the matteris: ClassLoader classLoader = sdkEnvironment.getRobolectricClassLoader();

aslak hellesoy

unread,
May 14, 2014, 6:16:52 AM5/14/14
to Cucumber Users
A Backend is a class responsible for loading glue code (step definitions and hooks). There is a Ruby one, a Groovy one etc. And of course a Java one (in cucumber-java).

The JavaBackend needs an ObjectFactory to instantiate the java classes it finds. There is one for Spring, one for Guice and several other DI containers. And there is one for Android.

Putting cucumber-android on your classpath should give you what you need. If you're using maven it should pull in all dependencies.

Aslak
 

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

aslak hellesoy

unread,
May 14, 2014, 9:42:28 AM5/14/14
to Marco, Cucumber Users
Please don't email me privately: http://cukes.info/posting-rules (scroll down to 5)

On Wed, May 14, 2014 at 2:24 PM, Marco <marc....@gmail.com> wrote:
Hi Aslak, thank for your reply.

What you mean with "Put cucumber-android on your classpath"?

I don't know how to answer that in a different way. What part don't you understand?
 
My project test contains all cucumber jars and I added them to path,

There is 20 different cucumber jars, and you're not supposed to use all of them, only the ones that are relevant to your environment.


For android you need cucumber-android, cucumber-java and cucumber-core.
 
in fact, if I load features with the test classLoader:
ClassLoader classLoader = testClass.getClassLoader();
the stepdefs are executed correctly

I've to add cucumber-android to the robolectric project's path?


I'm not familiar with roboelectric, so I cannot answer that.
Reply all
Reply to author
Forward
0 new messages