Thursday, May 16, 2013
Mocking a Static Method
import the following:
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
Add the following annotations to the class:
@RunWith(PowerMockRunner.class)
@PrepareForTest(Static_Class.class)
public class ClassNameTest
And mock the class with the following Code.
PowerMock.mockStatic(Static_Class.class);
expect(
StaticClass.Static_Method(params)
.andReturn(mockObject);
PowerMock.expectLastCall().atLeastOnce();
PowerMock.replayAll();
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment