@Target(value={TYPE,METHOD})
@Retention(value=RUNTIME)
@Documented
@Inherited
public @interface PrepareOnlyThisForTest
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 the
value()
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 or
public 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 the PrepareForTest
annotation manipulates the full class
hierarchy. This annotation is recommend if you want full control over which
classes that are byte-code manipulated.
Modifier and Type | Optional Element and Description |
---|---|
ByteCodeFramework |
byteCodeFramework |
java.lang.String[] |
fullyQualifiedNames |
java.lang.Class<?>[] |
value |
public abstract java.lang.Class<?>[] value
public abstract ByteCodeFramework byteCodeFramework