What does the annotation @PrepareForTest
in PowerMockito really mean?
What should be placed there apart of classes which have static methods?
What does the annotation @PrepareForTest
in PowerMockito really mean?
What should be placed there apart of classes which have static methods?
That annotation tells PowerMock(ito) that the listed classes will need to be manipulated on the byte code level.
You need to "prepare for test" all these classes X of which you want to
new()
used in another class XPowerMockito.when(spy, "privateMethodNameAsString").then...
In other words:
X.doStatic()
, you have to prepare the class X.new Y(...)
, you have to prepare the class X that contains that new
statement.