ITeye博客

mock System class with powermock

jwu · 2013-12-02 14:13 · java language · UT · 编程语言 · Markdown

  1. Use the @RunWith(PowerMockRunner.class) annotation at the class-level of the test case.
  2. Use the @PrepareForTest({ClassThatCallsTheSystemClass.class}) annotation at the class-level of the test case.
  3. Use mockStatic(SystemClass.class) to mock the system class then setup the expectations as normally.
  4. EasyMock only: Use PowerMock.replayAll() to change to replay mode.
  5. EasyMock only: Use PowerMock.verifyAll() to change to verify mode.

ref: https://code.google.com/p/powermock/wiki/MockSystem

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。