测试类模板
@RunWith(PowerMockRunner.class)
@PrepareForTest({CollaboratorWithStaticMethods.class})
public class CollaboratorWithStaticMethodsTest {
@Test
public void testFirstMethod() {
}
}
静态方式调用当前类的其他静态方法时,如何写单元测试
public static String forthMethod() {
String str = firstMethod("John");
return str + "Good morning!";
}
@Test
public void testForthMethod() {
PowerMockito.spy(CollaboratorWithStaticMethods.class);
PowerMockito.when(CollaboratorWithStaticMethods.firstMethod(anyString())).thenReturn("test");
String result = CollaboratorWithStaticMethods.forthMethod();
Assert.assertEquals("testGood morning!", result);
}
进入异常catch语句块