Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test failed after upgrade to gradle 4.4 #3846

Closed
hxlich opened this issue Apr 4, 2018 · 10 comments
Closed

test failed after upgrade to gradle 4.4 #3846

hxlich opened this issue Apr 4, 2018 · 10 comments

Comments

@hxlich
Copy link

hxlich commented Apr 4, 2018

Description

After update Android Studio to 3.1, gradle update to version 4.4, test runs from Android Studio are broken with the following error:

java.lang.VerifyError: class org.robolectric.android.fakes.RoboMonitoringInstrumentation overrides final method specifyDexMakerCacheProperty.()V

	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
	at org.robolectric.internal.bytecode.SandboxClassLoader.maybeInstrumentClass(SandboxClassLoader.java:130)
	at org.robolectric.internal.bytecode.SandboxClassLoader.lambda$findClass$0(SandboxClassLoader.java:107)
	at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:50)
	at org.robolectric.internal.bytecode.SandboxClassLoader.findClass(SandboxClassLoader.java:106)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at org.robolectric.android.internal.ParallelUniverse.createInstrumentation(ParallelUniverse.java:308)
	at org.robolectric.android.internal.ParallelUniverse.initInstrumentation(ParallelUniverse.java:276)
	at org.robolectric.android.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:205)
	at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:335)
	at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:245)
	at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:130)
	at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:42)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:84)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

Steps to Reproduce

Robolectric & Android Version

  • compileSdkVersion 26
  • minSdkVersion 17
  • org.robolectric:robolectric:3.8
  • org.robolectric:shadows-support-v4:3.3.2

Link to a public git repo demonstrating the problem:

Sample code:

@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class)
public class MyFragmentTest {
    @Test
    public void testFragment_shouldNotBeNull() throws Exception {
        MyFragment fragment = (MyFragment) MyFragment.newInstance();
        SupportFragmentTestUtil.startFragment(fragment);
        assertNotNull(fragment);
    }
}
@pedrohfp
Copy link

I'm exactly with the same problem

@matejdro
Copy link

Same issue here. Robolectric blocks migration to 3.1.0 gradle plugin on our project because of this.

@brettchabot
Copy link
Contributor

See #3751

@matejdro
Copy link

matejdro commented Apr 15, 2018

This is not the same issue. #3751 is about using Robolectric together with Espresso test. But this issue happens without Espresso.

@brettchabot
Copy link
Contributor

The workaround should be the same though. Upgrade your com.android.support.test.runner/monitor dependency to 1.0.2-alpha1

How is your gradle file configured now wrt com.android.support.test dependencies ?

@matejdro
Copy link

matejdro commented Apr 15, 2018

I don't think you understand. I do not have com.android.support.test.runner in Robolectric's classpath at all. My build.gradle looks like this:

    testImplementation "org.robolectric:robolectric:$robolectricVersion"
    androidTestImplementation "com.android.support.test:runner:$espressoTestRunnerVersion"
    androidTestImplementation "com.android.support.test.espresso:espresso-core:$espressoCoreVersion"

Robolectric and test runner are not in the same classpath (Robolectric is in test, while test runner is in andoridTest, so they should not clash or even see each other).

@brettchabot
Copy link
Contributor

Sorry for the trouble...

I cannot find the link now but IIRC there is a gradle bug where androidTest dependencies leak into test.

Try this as a workaround:
testImplementation "com.android.support.test:monitor:1.0.2-alpha1"

@hxlich
Copy link
Author

hxlich commented Apr 16, 2018

@brettchabot thx for the workaround, it works for me

@matejdro
Copy link

matejdro commented Apr 21, 2018

After a week of not getting the error I can also confirm that workaround is working for me. Thanks!

@andrewclam1991
Copy link

I use testImplementation "com.android.support.test:monitor:1.0.2" confirm working still.

hubot pushed a commit to f-droid/fdroidclient that referenced this issue Aug 17, 2018
Sometimes the test suite just totally bombs out and fails on every single
job with the same Robolectric crash.  Adding this line seems to fix it.

robolectric/robolectric#3846

Here's the error:
java.lang.VerifyError: class org.robolectric.android.fakes.RoboMonitoringInstrumentation overrides final method specifyDexMakerCacheProperty.()V
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants