我使用EasyMock在我的測試中模擬對象。但是,我如何模擬在代碼中其他位置創建的對象?看看下面的psudo代碼。我想嘲笑WebService#getPersonById,我該怎麼做?如何模擬我無法在測試中實例化的對象?
public class Person {
public Person find(int id) {
WebService ws = new WebService();
return ws.getPersonById(id);
}
}
public class PersonTest {
testFind() {
// How do I mock WebService#getPersonById here?
}
}
+1 - 這是幾乎一模一樣我在我的(現在刪除的)答案中添加了什麼。 – 2011-01-26 16:58:51
+1好的答案。成爲老師的方式。 – jwir3 2011-01-26 17:08:44