Impossible RuntimeException: Stub with Robolectric

爱⌒轻易说出口 提交于 2019-12-01 23:37:45
acc15

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):

public class YourTestRunner extends RobolectricTestRunner
{
    public YourTestRunner(Class<?> testClass) throws InitializationError
    {
        super(RobolectricContext.bootstrap(YourTestRunner.class, testClass,
            new RobolectricContext.Factory()
            {
                @Override
                public RobolectricContext create()
                {
                    return new RobolectricContext()
                    {
                        @Override
                        public boolean useAsm() // this override does the trick
                        {
                            return false;
                        }

                        @Override
                        protected AndroidManifest createAppManifest()
                        {
                            return new AndroidManifest(
                                new File("YourApp/src/main/android/AndroidManifest.xml"),
                                new File("YourApp/src/main/android/resources"));
                        }
                    };
                }
            }));
    }

    @Override
    public void prepareTest(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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!