有一个构造函数:
public PodLinksActivity( PodLinksPlace place ){
super( MFactory.getView(), place);
// other methods
}
我怎么能stub MFactory.getView()静态方法与PowerMock或PowerMockito (Mockito)不做GWTTestCase?
谢谢!
// 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)