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

本文介绍如何利用PowerMock框架模拟系统级类的行为。主要包括:在测试类级别使用@RunWith(PowerMockRunner.class)注解;使用@PrepareForTest注解准备测试类;通过mockStatic方法模拟静态方法;在EasyMock中使用PowerMock.replayAll及PowerMock.verifyAll方法。
722

被折叠的 条评论
为什么被折叠?



