Questions tagged «roboguice»

2
如果在任何模块中都有模拟的实例,则在创建RoboGuice注射器时进程崩溃
我在单元测试中使用RoboGuice和AndroidMock框架时遇到问题。我创建了一个简单的项目来展示我的问题。在这里,我创建了一个模拟实例,并将其注册到RoboGuice中。但是该过程在“ setUp()”和“ test01()”方法之间崩溃。我猜想,如果任何模块内部都有模拟的实例,那么实际上在创建Injector时该过程就会崩溃。 如果我将模拟的实例替换为实现该接口的类的实例,则一切正常。 有人知道如何解决此问题吗? 这是我的测试代码: 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);//Comment this string to get into the test01() method MyApplication.setMyModule(myMockModule); super.setUp(); } public void test01() { //It never comes here } } …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.