Skip to content
Search or jump to…
Pull requests
Issues
Marketplace
Explore
Sign out
You don’t have any verified emails. We recommend verifying at least one email.
Email verification helps our support team verify ownership if you lose account access and allows you to receive all the notifications you ask for.
Watch 162
Star 1,935 Fork 376 powermock/powermock
Code Issues 294 Pull requests 2 Projects 4 Wiki Insights
Getting Started
Arthur Zagretdinov edited this page on 3 Sep 2017 · 4 revisions
Pages 40
Getting Started
Downloads
Motivation
Common
PowerMock Configuration
Bypass Encapsulation
Suppress Unwanted Behavior
Test Listeners
Mock Policies
Mock system classes
EasyMock
Mockito
Robolectric
TestNG
Code coverage with JaCoCo
Delegate to another JUnit Runner
Bootstrap using a JUnit Rule
Bootstrap using a Java Agent
OSGi
Release Notes
FAQ
Support
Contributors
Clone this wiki locally
https://github.com/powermock/powermock.wiki.git
Clone in Desktop
Getting Started
API's
PowerMock consists of two extension API's.
One for EasyMock and one for Mockito. To use PowerMock you need to depend on one of these API's as well as a test framework.
Currently PowerMock supports JUnit and TestNG. There are three different JUnit test executors available, one for JUnit 4.4+, one for JUnit 4.0-4.3 and one for JUnit 3 (deprecated).
There's one test executor for TestNG which requires version 5.11+ depending on which version of PowerMock you use.
Node: Since PowerMock 2.0 Supporting jUnit 3 will be dropped
Writing tests
Write a test like this:
@RunWith(PowerMockRunner.class)
@PrepareForTest( { YourClassWithEgStaticMethod.class })
public class YourTestCase {
...
}
Maven setup
JUnit
EasyMock JUnit Maven setup
Mockito JUnit Maven setup
Mockito2 JUnit Maven setup
TestNG
EasyMock TestNG Maven setup
Mockito TestNG Maven setup
Mockito2 TestNG Maven setup
Non maven users
EasyMock
JUnit: Download the EasyMock zip-file with PowerMock and all its dependencies and add those to your project.
TestNG: Download the EasyMock zip-file with PowerMock and all its dependencies and add those to your project.
Mockito
JUnit: Download the Mockito zip-file with PowerMock and all its dependencies and add those to your project.
TestNG: Download the Mockito zip-file with PowerMock and all its dependencies and add those to your project.
Need to combine PowerMock with another JUnit runner?
First try the JUnit Delegation Runner and if that doesn't work then try the PowerMockRule or PowerMock Java Agent.
Need to bootstrap using a JUnit rule?
The PowerMockRule makes this happen
Java agent based bootstrapping
Use the PowerMock Java Agent if you're having classloading problems when using PowerMock.
Need Tutorial ?
Clone the project from git using:
Using SSH
git clone git@github.com:powermock/powermock-examples-maven.git
Using HTTPS
git clone https://github.com/powermock/powermock-examples-maven.git
Check out version 1.7.1:
git checkout powermock-1.7.1
Step into the examples/tutorial/ folder and follow the instructions in the readme.txt file.
© 2018 GitHub, Inc.
Terms
Privacy
Security
Status
Help
Contact GitHub
API
Training
Shop
Blog
About
Press h to open a hovercard with more details.