@Target(value={TYPE,METHOD})
@Retention(value=RUNTIME)
@Documented
@Inherited
public @interface PrepareForTest
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.
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 or
public 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 the PrepareOnlyThisForTest
annotation
manipulates only the specified classes.
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