I have a problem using RoboGuice and AndroidMock frameworks in unit testing. I created a simple project to show my problem. Here I create a laughable instance and register it with RoboGuice. But the process crashes between the methods "setUp ()" and "test01 ()". As I believe, in fact, the process crashes when the injector is created, if in any module there is a fragmented instance inside.
If I replace the ridiculed instance with an instance of a class that implements the interface, everything works fine.
Does anyone know how to fix this problem?
Here is my test code:
public class testInjectMock extends RoboUnitTestCase<MyApplication> { protected void setUp() throws Exception { InterfaceToMock instance = AndroidMock.createNiceMock(InterfaceToMock.class); AndroidMock.expect(instance.SimpleMethod()).andStubReturn("Hello!"); MyModule myMockModule = new MyModule(); myMockModule.setMockedInstance(instance);
Source code of the module:
public class MyModule extends AbstractAndroidModule { protected InterfaceToMock mockedInstance; public void setMockedInstance(InterfaceToMock mockedInstance) { this.mockedInstance = mockedInstance; } @Override protected void configure() { if(mockedInstance != null) bind(InterfaceToMock.class).toInstance(mockedInstance); } }
Logcat output:
05-23 16:17:07.135: INFO/DEBUG(27): Build fingerprint: 'generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys' 05-23 16:17:07.135: INFO/DEBUG(27): pid: 2025, tid: 2031 >>> InjectMock.test <<< 05-23 16:17:07.145: INFO/DEBUG(27): signal 11 (SIGSEGV), fault addr 00000000 05-23 16:17:07.155: INFO/DEBUG(27): r0 0011b218 r1 43d1caa0 r2 00000000 r3 00000000 05-23 16:17:07.155: INFO/DEBUG(27): r4 43d1caa0 r5 0011b218 r6 451c0e30 r7 4000a958 05-23 16:17:07.155: INFO/DEBUG(27): r8 ad00f380 r9 00138de0 10 426bda34 fp 00138de0 05-23 16:17:07.155: INFO/DEBUG(27): ip 00000002 sp 451c0dc0 lr ad05ad1d pc ad05a804 cpsr 00000030 05-23 16:17:07.295: INFO/DEBUG(27):
java android eclipse roboguice
Andrey May 23 '11 at 18:29 2011-05-23 18:29
source share