Test double from Wikipedia
Test double - Wikipedia
In computer programming and computer science, programmers and developers employ a technique called automated unit testing to enhance the quality of the software. Frequently, the final release software consists of a complex set of objects or procedures interacting together to create the final result. In automated unit testing, it may be necessary to use objects or procedures that look and behave like their release-intended counterparts, but are actually simplified versions that reduce the complexity and facilitate testing. A test double is a generic (meta) term used for these objects or procedures.
Types of test doubles
Gerard Meszaros[1] identified several different terms for what he calls, "Test Doubles." Using his vocabulary, there are at least five types of Test Doubles:
- Test stub (used for providing the tested code with "indirect input")
- Mock object (used for verifying "indirect output" of the tested code, by first defining the expectations before the tested code is executed)
- Test spy (used for verifying "indirect output" of the tested code, by asserting the expectations afterwards, without having defined the expectations before the tested code is executed. It helps in recording information about the indirect object created)
- Fake object (used as a simpler implementation, e.g. using an in-memory database in the tests instead of doing real database access)
- Dummy object (used when a parameter is needed for the tested method but without actually needing to use the parameter)
For both manual and automated black box testing of service oriented architecture systems or microservices software developers and testers use test doubles that communicate with the system under test over a network protocol.[2][3] These test doubles are called different names depending on the tool vendor. A commonly used term is service virtualization. Other names used include API simulation, API mock,[4] HTTP stub, HTTP mock, over the wire test double[5] .[6]
Another form of test double is the Verified Fake, a Fake object whose behavior has been verified to match that of the real object using a set of tests that run against both the Verified Fake and the real implementation.[7]
While there is no open standard for test double and the various types, there is momentum for continued use of these terms in this manner. Martin Fowler used these terms in his article, Mocks Aren't Stubs[8] referring to Meszaros' book. Microsoft also used the same terms and definitions in an article titled, Exploring The Continuum Of Test Doubles.[9]
See also
- Mock object
- Software testing
- Service virtualization
- Comparison of API simulation tools
- List of unit testing frameworks
- Object-oriented programming
- Test-driven development
References[edit]
- ^ Meszaros, Gerard (2007). xUnit Test Patterns: Refactoring Test Code. Addison-Wesley. ISBN 978-0-13-149505-0.
- ^ Clemson, Toby "Testing Strategies in a Microservice Architecture", martinfowler.com, 18 November 2014. Retrieved on 07 December 2017.
- ^ Byars, Brandon. "Testing Microservices with Mountebank", Manning Publications, MEAP began March 2017. ISBN 9781617294778. Retrieved on 07 December 2017.
- ^ Bryant, Daniel "API Mocking Tool WireMock v2 Released with Improved Request Matching and Stub Management", InfoQ, 16 August 2016. Retrieved on 07 December 2017.
- ^ ThoughtWorks "Technology Radar, Tools: Mountebank", ThoughtWorks, November 2015. Retrieved on 07 December 2017.
- ^ Bulaty, Wojciech "Stubbing, Mocking and Service Virtualization Differences for Test and Development Teams", InfoQ, 19 February 2016. Retrieved on 07 December 2017.
- ^ Turner-Trauring, Itamar (2019). "Fast tests for slow services: why you should use verified fakes". Retrieved 2019-01-21.
- ^ Fowler, Martin (2007). "Mocks Aren't Stubs". Retrieved 2010-12-29.
- ^ Seemann, Mark (2007). "Exploring The Continuum Of Test Doubles". Retrieved 2010-12-29.
External links[edit]
Gerard Meszaros:
Martin Fowler:
- TestDouble, 17 January 2006
Open source:
- ELF Spy - Fakes and Spies in C++
- FakeIt - Mocks, Fakes and Spies in C++
- Google Mock - Mocking in C++
- jMock - Test Driven Development with Mocks
- Mockito - Mocking Framework for Java
- unittest.mock - Mocking with Python
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2017-05-31 在IIS中给某一个网站添加binding的坑
2017-05-31 Firefox中使用pac
2017-05-31 火狐浏览器设置bypass
2017-05-31 如何卸载visualsvn for visual studio
2016-05-31 perl的安装