我有一个构造函数:
public PodLinksActivity( PodLinksPlace place ){
super( MFactory.getView(), place);
// other methods
}
如何使用PowerMock或PowerMockito(Mockito)将MFactory.getView()静态方法存根以不创建GWTTestCase?
谢谢!
答案 0 :(得分:1)
// view you expect to pass as first super-arg
View view = mock(View.class);
// setup the MFactory class
PowerMockito.mockStatic(MFactory.class);
// mock the method you care about
PowerMockito.when(MFactory.class, "getView").thenReturn(view);
确保在测试类的顶部添加适当的PowerMock注释:
@RunWith(PowerMockRunner.class)
@PrepareForTest(MFactory.class)