假如有下面一个类DemoStatic,它里面定义了各种静态方法,这些静态方法可能是一些Utilities方法,辅助其它的类。
package mock.demo;首先,我们写一个测试类DemoStaticTest.java, 如下:
public class DemoStatic {
public static String sayHello() {
return "Hello";
}
public static String saySomething(String word) {
return word;
}
public static void sayAgain() {
System.out.println(getMyWord());
}
private static String getMyWord() {
return "This is my word";
}
}
注意在类的前面要加这个annotation:@RunWith(PowerMockRunner.class)
@PrepareForTest({DemoStatic.class})
public class DemoStaticTest {
}
@PrepareForTest({DemoStatic.class})<