PowerMockito模拟private static final类变量
作者:互联网
mock模拟private static final now=system.currentmills;
首先在测试类开头加上:
@prepareForTest({System.class})
Class A{
}
然后,在方法上添加:
powermockito.mockstatic(system.class);
powermockito.when(system.currentmills).thenreturn(now);
system.currentmills;
如果要mock模拟类的变量Class A {
private String a;
}
可以这样:
String a = "test";
ReflectionUtils.set(new A(),'a',a);
如果要mock模拟类的变量Class A {
private final String a;
}
可以这样:
String a = "test";
标签:PowerMockito,String,currentmills,system,private,static,Class,mock 来源: https://www.cnblogs.com/nizuimeiabc1/p/12173907.html