3

I am unable to get a new Robospock specification to run in Android Studio 3.0 beta 6 and gradle 3.4.1. The error I get when I run the test in Android Studio is:

java.lang.NoSuchMethodError: org.robolectric.annotation.Config$Implementation.<init>(Lorg/robolectric/annotation/Config;)V

    at org.robospock.internal.RoboSputnik.<clinit>(RoboSputnik.java:52)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    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:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

The spec looks like this:

import org.robolectric.annotation.Config
import org.robospock.RoboSpecification
@Config(constants = com.myapp.BuildConfig, sdk = 19, manifest='src/main/AndroidManifest.xml')
public class MyActivitySpec extends RoboSpecification {
  ...
}

My gradle dependencies are:

testImplementation 'org.robolectric:robolectric:3.4.2'
testImplementation('org.robospock:robospock:1.0.1') {
    exclude module: 'robolectric'
}

Above translates to all of robolectric transitive dependencies (quite large) and the following robospock dependencies:

\--- org.robospock:robospock:1.0.1
     \--- org.spockframework:spock-core:1.0-groovy-2.4
          +--- org.codehaus.groovy:groovy-all:2.4.1
          \--- junit:junit:4.12 (*)

I have also tried creating a custom Runner as follows:

public class MyTestRunner extends RobolectricTestRunner {

    public MyTestRunner(final Class<?> testClass) throws InitializationError {
        super(testClass)
    }

    @Override protected Config buildGlobalConfig() {
        return new Config.Builder().setApplication(com.me.MyApp).setConstants(com.myapp.BuildConfig).setSdk(19).setManifest('src/main/AndroidManifest.xml').build();
    }
}

And specified it on my specification using class annotation: @RunWith(MyTestRunner)

In this case I get the following error:

java.lang.Exception: No runnable methods

    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
    at org.robolectric.internal.SandboxTestRunner.<init>(SandboxTestRunner.java:43)
    at org.robolectric.RobolectricTestRunner.<init>(RobolectricTestRunner.java:77)

In case it is significant my run config in Android Studio is an Android Junit configuration.

TIA for any guidance.

Farrukh Najmi
  • 5,055
  • 3
  • 35
  • 54

2 Answers2

3

Robospock was not updated for almost a year now, so my best guess is it isn't compatible with the Robolectric version you provided.

testImplementation 'org.robolectric:robolectric:3.4.2'
testImplementation('org.robospock:robospock:1.0.1') {
    exclude module: 'robolectric'
}

You manually chose a different version, that the one supported by the library, which is 3.0.

The error is about missing Config$Implementation constructor, which is missing on the master: https://github.com/robolectric/robolectric/blob/master/annotations/src/main/java/org/robolectric/annotation/Config.java#L175

Fixing it would require updating the library.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Wojtek Erbetowski
  • 3,205
  • 5
  • 22
  • 37
  • You are my hero. Can I make robospock 1.0.1 work with robolectric 3.4.2 with a custom runner? If so, any suggestions on how to fix the "No runnable methods" problem I listed? – Farrukh Najmi Sep 21 '17 at 09:08
  • @FarrukhNajmi I think you need to update the library as it internally calls the given constructor. – Wojtek Erbetowski Sep 21 '17 at 13:13
1

try ElectricSpock. It is my project based on RoboSpock, which should work with Robolectric 3.4

Herman Cheung
  • 324
  • 3
  • 7
  • I am unable to get my robolectric test to run with the ElectricSpock project. I am getting the following exception. Can you tell me the how to get Robolectric 3.4.2 to work within Android Studio 3.0 beta 6: No such manifest file: build\intermediates\manifests\full\debug\--default android.content.res.Resources$NotFoundException: Resource ID #0x7f08005c at android.content.res.Resources.getValue(Resources.java:1013) at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager – Farrukh Najmi Sep 24 '17 at 17:29
  • Would you post your test code? It would be nice if you could file an issue over there so I can keep track of it. https://github.com/hkhc/electricspock/issues – Herman Cheung Sep 25 '17 at 02:08