开发者

GWT test with PowerMock and PowerMockito

开发者 https://www.devze.com 2023-02-22 22:22 出处:网络
I have a constructor: public PodLinksActivity( PodLinksPlace place ){ super( MFactory.getView(), place);

I have a constructor:

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

how can I stub the MFactory.getView() static method with PowerMock or PowerMockito (Mockito) for not making a GWTTestCase?

Thanks开发者_StackOverflow社区!


// 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);

Ensure that you add the appropriate PowerMock annotations at the top of your test class:

@RunWith(PowerMockRunner.class)
@PrepareForTest(MFactory.class) 
0

精彩评论

暂无评论...
验证码 换一张
取 消