PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.
Java
Latest commit 783e46f Nov 3, 2017 @thekingnothing thekingnothing [ci skip-release] Revert "1.7.4 release (previous 1.7.3) + release no…
…tes updated by CI build 708"

This reverts commit 51589ab.
Permalink
Failed to load latest commit information.
.github Update contributor guide Jun 16, 2017
config/checkstyle Add Checkstyle and configuration file Jul 8, 2017
docs [ci skip-release] Revert "1.7.4 release (previous 1.7.3) + release no… Nov 3, 2017
gradle Upgrade gradle [ci skip-release] Oct 31, 2017
powermock-api Fixed #849 PowerMock.replayAll does not handle mocks created by annot… Sep 16, 2017
powermock-classloading Fix Java 1.7 build: fix XStream and Objenesis tests. Aug 27, 2017
powermock-core Revert "Fixes #839 Removed deprecated code in PowerMock 2.0." Sep 10, 2017
powermock-modules Revert "Fixes #839 Removed deprecated code in PowerMock 2.0." Sep 10, 2017
powermock-reflect Fixed #849 PowerMock.replayAll does not handle mocks created by annot… Sep 16, 2017
powermock-release Revert "Fixes #839 Removed deprecated code in PowerMock 2.0." Sep 10, 2017
tests Fixed #849 PowerMock.replayAll does not handle mocks created by annot… Sep 16, 2017
.gitignore Fixed #755 @Mock annotation from easymock api does not work for two f… Sep 15, 2017
.travis.yml Fixes #826 Use Mockito Shipkit for CD Aug 27, 2017
CONTRIBUTING.md Update CONTRIBUTING.md Jun 18, 2017
LICENSE.txt Add distribution and shadow plugin. Finish with publishing to bintray. Jan 25, 2017
README.md Update README.md Nov 3, 2017
build.gradle Upgrade gradle [ci skip-release] Oct 31, 2017
gradle.properties Migration from maven to gradle Jan 25, 2017
gradlew Upgrade gradle [ci skip-release] Oct 31, 2017
gradlew.bat Upgrade gradle to 3.4.1 Mar 5, 2017
powermock.png Return back logo Jan 25, 2017
settings.gradle Revert "Fixes #839 Removed deprecated code in PowerMock 2.0." Sep 10, 2017
version.properties [ci skip-release] Revert "1.7.4 release (previous 1.7.3) + release no… Nov 3, 2017

README.md

PowerMock

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.

News

  • 2017-09-16: PowerMock 1.7.3 has been released. The release includes bugfix for #849. See release notes for details.
  • 2017-09-16: PowerMock 1.7.2 has been released. The first release with using Mockito Shipkit. See release notes for details.
  • 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.

Older News

Documentation

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.