首页 > 其他分享 >Difference between stub, mock and fake in Unit Test

Difference between stub, mock and fake in Unit Test

时间:2023-01-09 10:55:25浏览次数:39  
标签:real dummy used implementation certain stub between test mock

In unit testing, "stubs", "mocks", and "fakes" are all dummy implementations of functions or objects that are used to test the behavior of another piece of code. However, they differ in the degree to which they are configured and the role they play in the testing process.

 

A "stub" is a very simple dummy implementation of a function or object that is used to return a predetermined value or simulate a specific condition. Stubs are often used to provide input values for the code under test or to test error handling.

 

A "mock" is a more sophisticated dummy implementation that can be configured to verify that certain conditions are met during the test. Mocks can be set up to verify that certain functions are called, certain values are returned, or certain conditions are met.

 

A "fake" is a working implementation of a function or object that is used in place of the real implementation for testing purposes. Fakes are often used when the real implementation is too complex or time-consuming to set up for a test, or when the real implementation has external dependencies that are difficult to manage in a test environment.

 

In general, stubs are the most basic form of dummy implementation and are used to provide input values or simulate simple conditions. Mocks are more advanced and are used to verify the behavior of the code under test. Fakes are fully functional implementations that are used to substitute for the real implementation in tests.

标签:real,dummy,used,implementation,certain,stub,between,test,mock
From: https://www.cnblogs.com/chucklu/p/17036357.html

相关文章

  • Differences between the John Deere EDL v2 and the new EDL v3
    TheJohnDeerediagnosticadapterforthediagnosisofspecialequipmentandagriculturalmachineryJohnDeereandworksinconjunctionwiththeServiceAdviso......
  • 基于Mockito的Android应用单元测试
    Mockito是java开发中常用的Mock库,在Android应用单元测试中比较常见在实际的单元测试中,测试的类之间会有或多或少的耦合,导致无法顺利的进行测试,这是就可以使用Mockito,该库可......
  • spring boot——spring boot的基本配置——spring boot整合mybatis——本地实例运行—
          mapper层:packagecom.demo.mapper;importjava.util.List;importorg.apache.ibatis.annotations.Mapper;importorg.apache.ibatis.annotation......
  • vue3 mock获取数据
    创建api文件夹,在文件夹中创建mockAjax.js,和请求数据的api.js。importaxiosfrom'axios'importnprogressfrom'nprogress'import'nprogress/nprogress.css'const......
  • Mock Server的使用
    postman的MockServer使用必须注册一个postman账号才能使用1、创建MockServer1)点击postman左上角的New弹出新建窗口,点击MockServer2)设置参数如下第一步第二步......
  • 一文教会你mock(Mockito和PowerMock双剑合璧)
    作者:京东物流杨建民1.什么是MockMock有模仿、伪造的含义。Mock测试就是在测试过程中,对于某些不容易构造或者不容易获取的对象,用一个虚拟的对象来创建以便测试的测试方法。m......
  • postgresql/lightdb OVERLAPS 和 BETWEEN SYMMETRIC函数介绍
    PostgreSql/lightdb中有两个非常方便、有用的比较操作,OVERLAPS和BETWEENSYMMETRIC。1.OVERLAPS(重叠)OVERLAPS操作,用于检测两个日期范围是否重叠。举例:SELECT(......
  • mock.js模拟数据
    1.npm install mockjs2.在src目录下创建个mock文件夹3.mock文件夹下准备json数据(json数据必须格式化,不能留有空格)json需要的图片资源放在public文件夹下,会随dist打包原......
  • SQLServer中使用between查询日期
    SQLServer中字段是Datetime型以"YYYY-MM-DD00:00:00"存放的betweenand是包括边界值的,notbetween不包括边界值,不过如果使用betweenand限定日期需要注意,如果and后......
  • mockMVC
    引入依赖<!--junit5spring-test--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-t......