MockPartial

Arthur Zagretdinov edited this page Jun 15, 2017 · 2 revisions

Partial Mocking

Quick summary

  1. Use the @RunWith(PowerMockRunner.class) annotation at the class-level of the test case.
  2. Use the @PrepareForTest(ClassToPartiallyMock.class) annotation at the class-level of the test case.
  3. se PowerMock.createPartialMock(ClassToPartiallyMock.class, "nameOfTheFirstMethodToMock", "nameOfTheSecondMethodToMock") to create a mock object that only mocks the methods with name nameOfTheFirstMethodToMock and nameOfTheSecondMethodToMock in this class (let's call it mockObject).
  4. Use PowerMock.replay(mockObject) to change the mock object to replay mode.
  5. Use PowerMock.verify(mockObject) to change the mock object to verify mode.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.