我使用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