Possible Duplicate:
What is Object Mocking and when do I need it?
单元测试:解释模拟对象的有用性[重复]
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- doudieheng5322 2010-11-26 22:18关注
You might indeed start writing tests for B and implementing B as soon as you know you need it and then come back to A. But when you come back to A you might want to use a mock for B so that your test for A is really testing A and its interactions with B.
Part of the reason for this is there might be another class C that B uses to do some of its work. If you want to test A using a real B, you'll also need C, and of course the difficulty can extend further.
Using mocks you can make your test check only that A calls B methods when it should and deals properly with the responses that you tell your mock to give, rather than depending on a real implementation of B.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
- ¥15 求螺旋焊缝的图像处理
- ¥15 blast算法(相关搜索:数据库)
- ¥15 请问有人会紧聚焦相关的matlab知识嘛?
- ¥15 网络通信安全解决方案
- ¥50 yalmip+Gurobi
- ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
- ¥15 itunes恢复数据最后一步发生错误
- ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
- ¥100 H5网页如何调用微信扫一扫功能?