0

私はコンストラクタを持っています:

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

GWTTestCase を作成しないために、PowerMock または PowerMockito (Mockito) で MFactory.getView() 静的メソッドをスタブするにはどうすればよいですか?

ありがとう!

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 に答える