2011-04-07 80 views
0

我有一個構造函數:GWT測試與PowerMock和PowerMockito

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

我怎麼能存根與PowerMock或PowerMockito(的Mockito)不作出GWTTestCase的MFactory.getView()靜態方法?

謝謝!

回答

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) 
+0

同樣,你也可以使用磕碰API:存根(方法(MFactory.class,「getView」 ))。toReturn(視圖) – pickypg 2011-04-13 20:07:29