Unable to mock static methods in instrumentation tests

一曲冷凌霜 提交于 2019-12-05 17:53:05

PowerMock doesn't work with Espresso see this issue

You can use Powermock to mock static methods. I used it to mock Log.java class in my application. Have a look on the example below :

@RunWith(PowerMockRunner.class)
@PrepareForTest({Log.class})

public class PowermockStaticExample {

//fixme : complete with your members

@Before
public void setUp() throws Exception {
  PowerMockito.mockStatic(YourStaticClass.class);
  //Use Powermock annotation to mock what you want to
}

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