Which annotation is used to prepare a class for PowerMock’s static method mocking?
A) @PrepareForTest
B) @MockStatic
C) @Mock
D) @PowerMock
Answer:
A) @PrepareForTest
Explanation:
The @PrepareForTest annotation is used in PowerMock to prepare the class that contains static, final, or private methods for mocking. This annotation is essential for PowerMock to manipulate the bytecode of the class.
For example:
@RunWith(PowerMockRunner.class)
@PrepareForTest(ClassWithStaticMethods.class)
public class MyTest {
// Test methods here
}
In this example, the @PrepareForTest annotation is used to prepare ClassWithStaticMethods for mocking its static methods.