天天看點

單元測試--MOCK靜态方法

@RunWith(PowerMockRunner.class)
@PrepareForTest(A.class)
public class Test {
private B b = new B();
    @Test(expected = IllegalStateException.class)
    public void testIOException() throws Exception {

   PowerMockito.mockStatic(A.class);
   PowerMockito.when(A.method()).thenThrow(new IOException());

   b.service();

    }
}