单元测试术语概述(存根与模拟,集成与交互)? [英] An overview of unit testing terminology ( stub vs mock , integration vs. interaction )?

查看:55
本文介绍了单元测试术语概述(存根与模拟,集成与交互)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用了更多的单元测试,并且阅读了我可以在线获取的所有信息,并对许多术语感到困惑.结果,我可能在对话和Google搜索中错误地使用了这些术语.

I'm using more unit tests in my projects and reading all the information I can online and am getting confused by a lot of the terminology. As a result I'm probably using these terms incorrectly in conversation and google searches.

有人可以概述所有单元测试术语,例如假"类型以及测试类型(交互还是集成)?

Can somebody outline all the unit testing terms like the "fake" types as well as types of test ( interaction vs. integration )?

推荐答案

当谈到模拟与假货与存根时,人们实际上有几种不同的解释方式.我通常会借用马丁·福勒定义的含义:

When it comes to mocks vs. fakes vs. stubs, there are actually a few different ways that people interpret them. I usually borrow the meanings defined by Martin Fowler:

  1. 存根对象提供了有效的响应,但它是静态的-无论您传递什么输入,您都将始终获得相同的响应.
  2. 假对象的行为类似于真实对象,但是它们以一种更简单的方式进行处理-例如使用地图存储数据而不是真实数据库的DAO.
  3. 模拟对象用于模拟测试用例中-它们验证在这些对象上调用了某些方法.

交互测试是一个通用术语,是指确保对象之间的交互正确(确保调用了预期方法)的单元测试.这与状态(或经典)测试相反,状态测试不关心方法中会发生什么,只要结果状态正确即可.我在上面链接的Fowler文章中对这些类型的测试进行了比较.

Interaction testing is a general term that refers to unit tests which ensure that the interaction between objects is correct (making sure that expected methods are called). This is opposed to state (or classical) testing, which doesn't care what happens in the methods, so long as the resulting state is correct. These types of testing are compared in Fowler's article that I linked above.

集成测试确实不是单元测试的一个方面,它比单元测试.它需要使用不同的单元,并验证它们是否可以正常工作.

Integration testing really isn't an aspect of unit testing, it is a level above the unit tests. It takes different units and verifies that they work together correctly.

这篇关于单元测试术语概述(存根与模拟,集成与交互)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆