0

我有一个构造函数:

public PodLinksActivity( PodLinksPlace place ){
   super( MFactory.getView(), place);
    // other methods
}

如何使用 PowerMock 或 PowerMockito (Mockito) 存根 MFactory.getView() 静态方法以不制作 GWTTestCase?

谢谢!

4

1 回答 1

2
// 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) 
于 2011-04-13T20:04:00.103 回答