PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.
Java
Latest commit 80f006a Jun 18, 2017 @johanhaleby johanhaleby committed on GitHub Update README.md
Permalink
Failed to load latest commit information.
.github Update contributor guide Jun 16, 2017
gradle Impl #623 Powermock Configuration (#796) May 29, 2017
powermock-api Wipe out dirty hack with replacing MockMatchersBinder to fix issue wi… Jun 13, 2017
powermock-classloading Fix JavaDoc issues Jun 10, 2017
powermock-core Update JavaDoc Jun 15, 2017
powermock-modules Mark jUnit 3 classes as deprecated Jun 15, 2017
powermock-reflect Fix issue #731 No methods matching the name(s) get were found in the … Jan 28, 2017
powermock-release Remove pom file. Jan 25, 2017
tests Implement #801 PowerMock Configuration: Global Ignore Jun 10, 2017
.gitignore #753 issue fix to upgrade code to be compatible with later versions o… Mar 1, 2017
.travis.yml Migration from maven to gradle Jan 25, 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 Jun 18, 2017
build.gradle Fix #793 PowerMockMaker for Mockito 2 (#795) May 26, 2017
changelog.txt Update changelog Jun 10, 2017
generate_javadoc.sh Added mockito2 and common library to javadoc generation Apr 29, 2016
gradle.properties Migration from maven to gradle Jan 25, 2017
gradlew Upgrade gradle to 3.4.1 Mar 5, 2017
gradlew.bat Upgrade gradle to 3.4.1 Mar 5, 2017
powermock.png Return back logo Jan 25, 2017
settings.gradle Fix #793 PowerMockMaker for Mockito 2 (#795) May 26, 2017
version.properties [Gradle Release Plugin] - new version commit: 'powermock-1.7.1'. Jun 16, 2017

README.md

PowerMock

Build Status Maven Central Javadoc

Usage status: Mockito: Reference Status Easymock: Reference Status jUnit: Reference Status TestNG Reference Status

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-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
  • 2016-11-04: PowerMock 1.6.6 is released with bug fixes and other improvements. See release notes and change log for details.

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.