gpt4 book ai didi

ruby-on-rails - 使用 rspec,对模拟对象和 stub 对象之间的区别感到困惑?

转载 作者:行者123 更新时间:2023-12-04 07:39:25 26 4
gpt4 key购买 nike

mock 和 stub 之间有什么区别,它们在我看来都很相似?

如果有人能给出一个真实世界的例子来说明什么时候使用哪个,或者它们可以互换,但是有一个最佳实践,比如什么时候使用模拟或 stub ,那就太好了?

最佳答案

这是大多数文章中的引用,非常通用且解释清楚:

http://martinfowler.com/articles/mocksArentStubs.html

简而言之:

Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'.

Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

关于ruby-on-rails - 使用 rspec,对模拟对象和 stub 对象之间的区别感到困惑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6062085/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com