Skip to content Skip to sidebar Skip to footer

Impossible Runtimeexception: Stub With Robolectric

I've spent hours trying to figure this out. I'm using Maven to build and test a project in IntelliJ IDEA with Robolectric. I have Robolectric declared before Android in the POM, an

Solution 1:

I'm have the same problem as you. And also one additional.

useless text cut

Update 1.

Found this issue on github: https://github.com/pivotal/robolectric/issues/426

Some peoples talk that on mac os it works..

Update 2.

Found workaround (comment by esam091):

publicclassYourTestRunnerextendsRobolectricTestRunner
{
    publicYourTestRunner(Class<?> testClass)throws InitializationError
    {
        super(RobolectricContext.bootstrap(YourTestRunner.class, testClass,
            newRobolectricContext.Factory()
            {
                @Overridepublic RobolectricContext create()
                {
                    returnnewRobolectricContext()
                    {
                        @OverridepublicbooleanuseAsm()// this override does the trick
                        {
                            returnfalse;
                        }

                        @Overrideprotected AndroidManifest createAppManifest()
                        {
                            returnnewAndroidManifest(
                                newFile("YourApp/src/main/android/AndroidManifest.xml"),
                                newFile("YourApp/src/main/android/resources"));
                        }
                    };
                }
            }));
    }

    @OverridepublicvoidprepareTest(Object test)
    {
        RoboGuice.injectMembers(Robolectric.application, test);
    }
}

Specify @RunWith(YourTestRunner.class) on each test which uses Android API.

Update 3.

Issue fixed: https://github.com/pivotal/robolectric/pull/458

Post a Comment for "Impossible Runtimeexception: Stub With Robolectric"