Overriding debug module in tests

爷,独闯天下 提交于 2019-12-05 21:51:31

What I've done this far (and I'm not entirely sure this will scale yet) is create a static test module class in my tests.

   @Module(
            injects = {
                    SharedPreferences.class
    })

      static  class TestModule {
            @Provides @Singleton SharedPreferences provideSharedPreferences(){
                return Mockito.mock(SharedPreferences.class);
            }
    }

And in the setup() method I inject the test module

  @Before
    public  void setUp(){
        ObjectGraph.create(new TestModule()).inject(this);
}

I then @Inject the mocked class:

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