說我有下面的代碼,這是不能被修改:測試不友好的代碼
class A {
public doSomething() {
// lots of business logic
data = obtainData();
// lots of other business logic which depends on data
}
private obtainData() {
// connect to the database
// send web requests
// send manned missions to the moon
// process the obtained data
return data;
}
}
什麼是測試這樣的代碼的最佳做法?我想確保doSomething()
做它應該做的事情,但我想提供它與已知的數據,而不是運行obtainData()
內的代碼。
私人而不是保護......哎呀。:-( – 2011-05-28 11:20:59
@Denis,確實... – rid 2011-05-28 11:21:45
@Denis:私人有什麼問題? – zerkms 2011-05-28 11:22:31