Annotation Type PrepareOnlyThisForTest
-
@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented @Inherited public @interface PrepareOnlyThisForTest
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.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
PrepareForTest
annotation is that this annotation only modifies the specified classes whereas thePrepareForTest
annotation manipulates the full class hierarchy. This annotation is recommend if you want full control over which classes that are byte-code manipulated.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description ByteCodeFramework
byteCodeFramework
java.lang.String[]
fullyQualifiedNames
java.lang.Class<?>[]
value
-
-
-
-
byteCodeFramework
ByteCodeFramework byteCodeFramework
- Default:
- org.powermock.core.classloader.ByteCodeFramework.Javassist
-
-