Process crashes during creation of RoboGuice injector, if there is a mocked instance in any module

后端 未结 2 1228
我寻月下人不归
我寻月下人不归 2021-02-01 11:32

I have a problem with using RoboGuice and AndroidMock frameworks in unit testing. I\'ve created a simple project to show my problem. Here I create a mocked instance and register

2条回答
  •  情话喂你
    2021-02-01 12:29

    Unfortunately this is a bug in Android itself. See the bug report here. The VM crashes when it tries to look for annotations on a Proxy, which is what AndroidMock uses when mocking an interface.

    The workaround is to create in instance of a class that implements the interface, as you pointed out in your question. You could try making a pure abstract class that implements the interface without implementing any methods, then use AndroidMock to mock that class instead of the interface. This should avoid the creation of a Proxy.

提交回复
热议问题