Annotation Type PrepareForTest
-
@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented @Inherited public @interface PrepareForTest
This annotation tells PowerMock to prepare certain classes for testing. Classes needed to be defined using this annotation are typically those that needs to be byte-code manipulated. This includes final classes, classes with final, private, static or native methods that should be mocked and also classes that should be return a mock object upon instantiation.This annotation can be placed at both test classes and individual test methods. If placed on a class all test methods in this test class will be handled by PowerMock (to allow for testability). To override this behavior for a single method just place a
@PrepareForTest
annotation on the specific test method. This is useful in situations where for example you'd like to modify class X in test method A but in test method B you want X to be left intact. In situations like this you place a@PrepareForTest
on method B and exclude class X from thevalue()
list.Sometimes you need to prepare inner classes for testing, this can be done by suppling the fully-qualified name of the inner-class that should be mocked to the
fullyQualifiedNames()
list.You can also prepare whole packages for test by using wildcards:
@PrepareForTest(fullyQualifiedNames="com.mypackage.*")
The annotation should always be combined with the
@RunWith(PowerMockRunner.class)
if using junit 4.x orpublic static TestSuite suite() throws Exception { return new PowerMockSuite(MyTestCase.class); }
if using junit3.The difference between this annotation and the
PrepareOnlyThisForTest
annotation is that this annotation modifies the specified classes and all its super classes whereas thePrepareOnlyThisForTest
annotation manipulates only the specified classes.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.String[]
fullyQualifiedNames
java.lang.Class<?>[]
value
-