博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
What's the difference between a stub and mock?
阅读量:7126 次
发布时间:2019-06-28

本文共 1166 字,大约阅读时间需要 3 分钟。

I believe the biggest distinction is that a stub you have already written with predetermined behavior. So you would have a class that implements the dependency (abstract class or interface most likely) you are faking for testing purposes and the methods would just be stubbed out with set responses. They wouldn't do anything fancy and you would have already written the stubbed code for it outside of your test.

A mock is something that as part of your test you have to setup with your expectations. A mock is not setup in a predetermined way so you have code that does it in your test. Mocks in a way are determined at runtime since the code that sets the expectations has to run before they do anything.

Tests written with mocks usually follow an initialize -> set expectations -> exercise -> verify pattern to testing. While the pre-written stub would follow an initialize -> exercise -> verify. The purpose of both is to eliminate testing all the dependencies of a class or function so your tests are more focused and simpler in what they are trying to prove.

I hope that helps.

 

reference:

, posted by Martin Flower,2007.

 ,stackoverflow

The art of unit testing.

 

 

 

转载地址:http://ynhel.baihongyu.com/

你可能感兴趣的文章
Learning Entity Framework(1)
查看>>
Learning EntityFramework(3)
查看>>
bzoj 3028 食物——生成函数
查看>>
MongoDB资料汇总
查看>>
写给运维兄弟
查看>>
myeclips快捷键和自动提示设置
查看>>
《GettingThingsDone》--GTD学习笔记(三)-GTD的三个关键原则
查看>>
libvirt(virsh命令总结)
查看>>
OD调试6—使未注册版软件的功能得以实现
查看>>
I.MX6 查找占用UART进程
查看>>
Ubuntu 搭建 LAMP 服务器
查看>>
The Elements of Programming Style
查看>>
简述一下src与href的区别
查看>>
跨域请求被拒绝的问题
查看>>
第六天
查看>>
POJ 1256:Anagram
查看>>
cocos2dx 云彩特效
查看>>
poj3140(树的dfs)
查看>>
Castle ActiveRecord的一对多问题
查看>>
VM安装系统时提示硬件不支持(unsupported hardware detected)
查看>>