【发布时间】:2010-07-15 15:23:44
【问题描述】:
假设我需要从遗留代码中为以下类添加单元测试(目前没有单元测试)。它只是一个简单的地图或字典。
function Map(...) { ... }
Map.prototype.put = function (key, value) {
// associate the value with the key in this map
}
Map.prototype.get = function (key) {
// return the value to which the specified key is mapped, or undefined
// if this map contains no mapping for the key
}
Map.prototype.equals = function (obj) { ... }
// ... and more bound functions
似乎没有办法一次只测试一个功能。例如,您不能在不调用 put() 的情况下测试 get()。如何对此进行单元测试?
【问题讨论】:
-
如果我们知道 put 和 get 做什么会很有帮助。
-
它只是一个简单的字典,就像 java.util.Map 或 Python 的 dict