PowerMockito.suppress()
suppress()
is one of the most powerful API's provided by PowerMock.
With suppress()
you can manipulate bytecode to skip executing any method or constructor.
For example, lets say you had an class which extended an library or code that you don't own, you can suppress its constructor.
Here, our source class extends CustomLibClass
which we do not need to test. But creating a object of ExampleClass
will also call constructor of CustomLibClass
. This can be avoided if we tell Powermock to suppress constructor of CustomLibClass
.
Note: keep in mind, if you need to manipulate behavior (byte code) of any class, as we are doing in case of suppress constructor, we need to add ExampleClass.class
in @PrepareForTest
.
Last updated