堆栈是通过链表实现的。什么时候有效,什么时候无效?
问问题
3141 次
2 回答
5
适当的单元测试取决于您的特定接口(黑盒测试)以及您的特定实现(玻璃盒测试)。对于堆栈,我希望测试一些东西:
- 可以将项目压入堆栈并将其弹出。
- 当将多个不同的项目压入堆栈时,重复弹出以相反的顺序返回它们。
- 未初始化的堆栈为空。
- 已推送项目的堆栈是非空的。
- 已推送并随后移除项目的堆栈是空的。
- 在没有项目时尝试弹出会导致记录的失败类型,无论是返回 NULL、抛出异常还是中止程序。
总结一下:
- 基本功能。
- 订单属性。
- 空性不变。
- 故障模式。
Note that what needs to be tested would be different for other datastructures. Typically, the way to go about creating this set of tests is to create a unit test for each function that confirms that each guarantee made by the documentation is upheld, and that it is upheld for all code paths through the function. Furthermore, one should test documented failure modes to confirm they fail in the expected manner.
于 2011-02-16T08:04:53.903 回答