【发布时间】:2009-08-12 18:59:23
【问题描述】:
继续另一个关于测试的类似问题 (see here)。我将使用一个类似的示例(伪代码)
class LinkDisplayer
method constructor(LinkStorage)
method displayLatestLinksByCategory(number_of_them)
class LinkStorage
method saveLink(Link)
method retrieveLatestLinksByCategory(category, number_of_them)
class Link
method getUrl()
method getDescription()
method getCategory()
所以 linkDisplayer 使用 LinkStorage 来获取链接。我要测试的行为是“shouldDisplayLatestLinks”。在我的测试中,我是否需要模拟 LinkStorage,并让它返回具有模拟 getUrl() 等行为的模拟 Link 对象?
测试“叶子”类很容易,但我仍然很难找到测试其他类的方法。
【问题讨论】: