Why we need PowerMock?

Although Mockito is most popular Mocking Library for Java Developers, But there are certain cases where Simple Mockito does not work. For Example, if your codebase uses any Singleton, you cannot mock them with Simple Mockito.

There are many other use cases, such as:

  1. Mock Static Methods

  2. Mock Final Classes and Methods

  3. Inject mock for object creation with whenNew()

  4. suppress(), stub() or replace() any method of a Class.

  5. Suppress static initialisation.

  6. Invoke private methods.

  7. Inject field with WhiteBox

Last updated