這是我第一次嘗試使用反射進行單元測試,並且我有這個疑問。通過反射檢查局部變量值的變化
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
}
}
現在,在上面的片段,我可以使用反射獲取變量temp
的初始值。我想知道,如果變量的值在執行代碼時發生變化,我怎麼才能得到temp
的新值?是一個全新的反思,所以如果這聽起來很愚蠢,請耐心等待。
P.S實際的測試代碼並不是那麼簡單。我有一種感覺,我不能使用反射或powermock單元測試最後的if
條件。
感謝我用詹金斯建立鏈接^^ – noMAD 2012-08-06 15:26:04