Skip to content
PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.
Branch: release/2.x
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update contributor guide Jun 16, 2017
config/checkstyle Fixes #727 Use ByteBuddy to instrument classes instead Javassist: imp… Apr 22, 2018
docs 2.0.5 release (previous 2.0.4) + release notes updated by CI build 833 Jan 25, 2020
gradle Enable local build in IDE without setting ENV Dec 19, 2019
powermock-api fix Static mocking broken for Mockito >= 2.26.1 (#997) Aug 31, 2019
powermock-classloading Fixes #888: Disable Security of X-Stream (#962) Dec 25, 2018
powermock-core [ci maven-central-release] Fixes #979 Generalise getting current java… Apr 21, 2019
powermock-modules [ci maven-central-release] Fix changing final fields on Java 12 (#1010) Oct 16, 2019
powermock-reflect Handle primivite data types Jan 10, 2020
powermock-release Fixes #727 Use ByteBuddy to instrument classes instead Javassist: add… Apr 22, 2018
tests Fixes #685 : Add new method display name pattern for providing compat… Aug 31, 2019
.gitignore Fix issue #945: update gitignore. add eclipse file to ignore. Nov 3, 2018
.travis.yml [ci skip] Remove building wiht bytebuddy class loader from travis bui… Oct 24, 2018 Update Jun 18, 2017
LICENSE.txt Add distribution and shadow plugin. Finish with publishing to bintray. Jan 25, 2017 Fixed some typos Aug 17, 2019
build.gradle fix Static mocking broken for Mockito >= 2.26.1 (#997) Aug 31, 2019 Migration from maven to gradle Jan 25, 2017
gradlew Upgrade gradle to 4.3 Mar 12, 2018
gradlew.bat Upgrade gradle to 3.4.1 Mar 5, 2017
powermock.png Return back logo Jan 25, 2017
settings.gradle Fixes #958 convert constructors of nested classes to public as well (#… Apr 21, 2019 2.0.5 release (previous 2.0.4) + release notes updated by CI build 833 Jan 25, 2020


Build Status Maven Central Download Javadoc

Writing unit tests can be hard and sometimes good design has to be sacrificed for the sole purpose of testability. Often testability corresponds to good design, but this is not always the case. For example final classes and methods cannot be used, private methods sometimes need to be protected or unnecessarily moved to a collaborator, static methods should be avoided completely and so on simply because of the limitations of existing frameworks.

PowerMock is a framework that extends other mock libraries such as EasyMock with more powerful capabilities. PowerMock uses a custom classloader and bytecode manipulation to enable mocking of static methods, constructors, final classes and methods, private methods, removal of static initializers and more. By using a custom classloader no changes need to be done to the IDE or continuous integration servers which simplifies adoption. Developers familiar with the supported mock frameworks will find PowerMock easy to use, since the entire expectation API is the same, both for static methods and constructors. PowerMock aims to extend the existing API's with a small number of methods and annotations to enable the extra features. Currently PowerMock supports EasyMock and Mockito.

When writing unit tests it is often useful to bypass encapsulation and therefore PowerMock includes several features that simplifies reflection specifically useful for testing. This allows easy access to internal state, but also simplifies partial and private mocking.

Please note that PowerMock is mainly intended for people with expert knowledge in unit testing. Putting it in the hands of junior developers may cause more harm than good.


  • 2019-04-21: PowerMock 2.0.2 has been released and is avaliable in Maven Central. The release includes fixes for issue with PowerMock JavaAgent and the latest JDK and a security issue with the build script.
  • 2019-01-07: PowerMock 2.0.0 has been released. Main changes: offical supporting Mockito 2.x and dropping supporting Mockito 1.x. This release also supports Java 9. Other change read in release notes.
  • 2017-08-12: PowerMock 1.7.1 has been released with one, but significant change: the old API for verifying static mock has been deprecated and a new one has been added. Old API will be removed in version PowerMock 2.0 due to incompatibility with Mockito Public API.
  • 2017-06-16: PowerMock 1.7.0 has been released with support for Mockito 2 (not only beta versions) and new features such as global @PowerMockIgnore as well as bug fixes and other improvements. See release notes and change log for details.
  • 2017-02-03: Johan blogs about how to mock slf4j with PowerMock at his blog

Older News


Contributing to PowerMock

Please, read the guideline for a new contributor before start.

Support and discussion

Join the mailing-list here for questions, feedback and support.

You can’t perform that action at this time.