PowerMock Configuration

Arthur Zagretdinov edited this page Aug 13, 2017 · 4 revisions

PowerMock Configuration

   Feature avaliable since PowerMock 1.7.0

As of version of 1.7.0 it's possible to globally configure PowerMock. This configuration is applied to all test classes that in the classpath. You may enable the configuration by creating by adding this file to the classpath:

org/powermock/extensions/configuration.properties

Global @PowerMockIgnore

By default PowerMock loads all classes with its MockClassLoader. The classloader loads and modified all classes except:

  • system classes. They are deferred to system classloader
  • classes located in packages that are specified as ignored.

Before 1.7.0 the only one way to ignore a package was to use the @PowerMockIgnore annotation:

 @PowerMockIgnore("org.myproject.*")
 @PrepareForTest(MyClass.class)
 @RunWith(PowerMockRunner.class)
 public class MyTest {
 ...
 }

In some cases the only way to avoid certain classloading related issues is to use @PowerMockIgnore and this used to imply that @PowerMockIgnore was copied and pasted in many tests.

But since PowerMock 1.7.0 you can specify packages to ignore using the configuration file:

powermock.global-ignore="org.myproject.*"

Multiple packages/classes can be specified using comma:

powermock.global-ignore="org.myproject.*","org.3rdpatproject.SomeClass"

Example of using PowerMock Configuration for global @PowerMockIgnore.

Mockito mock-maker-inline

PowerMock can delegate calls to another MockMaker, these tests are run without PowerMock. This can be configured by adding the following property to configuration file:

mockito.mock-maker-class=mock-maker-inline

Example of using Mockito mock-maker-inline with PowerMock

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.