My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
GettingStarted  
Updated Apr 5, 2012 by johan.ha...@gmail.com

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. There's one test executor for TestNG which requires version 5.11+ depending on which version of PowerMock you use.

Writing tests

Write a test like this:

@RunWith(PowerMockRunner.class)
@PrepareForTest( { YourClassWithEgStaticMethod.class })
public class YourTestCase {
...
}

Sample code is available in subversion:

JUnit 3 requires a different setup by creating a suite, since test runners are not available. Please view some examples:

Maven setup

JUnit

TestNG

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.

Or

You could also download the EasyMock jar-file or Mockito jar-file in a single file and then download the dependencies separately.

Need to bootstrap using a JUnit rule?

Java agent based bootstrapping

Use the PowerMock Java Agent if you're having classloading problems when using PowerMock.

Comment by googelyb...@gmail.com, Dec 12, 2010

Hi, the links to the code examples on this page appear to be broken (under "Writing tests")

Comment by project member johan.ha...@gmail.com, Dec 12, 2010

Fixed, thanks for pointing out.

Comment by cndoublehero@gmail.com, Dec 16, 2010
please check the "Mocking private methods with JUnit 3" link.It cann't work now.
Comment by cndoublehero@gmail.com, Dec 16, 2010

Is there any chance that you guys can put all those help documents into a ZIP file so we can download from the Downloads page?


Sign in to add a comment
Powered by Google Project Hosting