【发布时间】:2012-08-06 00:32:29
【问题描述】:
这是我第一次尝试使用反射进行单元测试,我有这个疑问。
Class Example {
public static Map<Something, Something> someMethod()
{
int temp = -1;
//Some implementation which might change the value of temp
//depending on other cases
if(temp == -1)
//Do something and return something
else
//return null
}
}
现在在上面的sn-p中,我可以通过反射得到变量temp的初始值。我想知道,如果变量的值在执行代码时发生变化,我怎样才能获得temp 的新值?我完全是反射新手,所以如果这听起来很愚蠢,请容忍。
P.S 正在测试的实际代码并非如此简单。我有一种感觉,如果不使用反射或 powermock,我无法对最后一个 if 条件进行单元测试。
【问题讨论】:
标签: java reflection junit