`
tracyhuyan
  • 浏览: 80319 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Mock static method

 
阅读更多

Mock static Class:   

 
byte[] a = {};
SetReader exp = new SetReader();

PowerMock.mockStatic(SetReader.class);       
EasyMock.expect(SetReader.parseFrom(EasyMock.aryEq(a))).andReturn(exp);
PowerMock.replay(SetReader.class);
       
PowerMock.verify(SetReader.class);

 

refer to:  http://code.google.com/p/powermock/wiki/MockStatic

 

  1. Use the @RunWith(PowerMockRunner.class) annotation at the class-level of the test case.
  2. Use the @PrepareForTest(ClassThatContainsStaticMethod.class) annotation at the class-level of the test case.
  3. Use PowerMock.mockStatic(ClassThatContainsStaticMethod.class) to mock all methods of this class.
  4. Use PowerMock.replay(ClassThatContainsStaticMethod.class) to change the class to replay mode.
  5. Use PowerMock.verify(ClassThatContainsStaticMethod.class) to change the class to verify mode.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics