Martin Gross bio photo

Martin Gross

Solution seeker, building things, often in software.

Twitter Google+ LinkedIn Github

Mock objects are simulated objects that mimic the behavior of real objects in controlled ways.

Mockito is my favourite mocking framework for Java for writing mock objects usable by unit tests.

Here is an example:

But sometimes you need to mock something which Mockito can’t handle.

PowerMock is an extension to Mocking frameworks like Mockito. It extends these frameworks to mock things like static methods or constructors.

The PowerMock website has a good page explaining how to use PowerMock with Mockito .