Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robospock initializationError NoSuchMethodError with Android Studio 3.0

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.

like image 744
Farrukh Najmi Avatar asked Jan 01 '26 18:01

Farrukh Najmi


1 Answers

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.

like image 57
Wojtek Erbetowski Avatar answered Jan 03 '26 09:01

Wojtek Erbetowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!