gpt4 book ai didi

unit-testing - 用于单元测试的 stub 有什么问题?

转载 作者:行者123 更新时间:2023-12-03 21:19:39 24 4
gpt4 key购买 nike

我刚看了这个搞笑YouTube Video about unit testing (这是希特勒用假字幕咀嚼他的团队没有做好单元测试——如果你幽默受损,跳过它)在那里 stub 受到严厉批评。但我不明白 stub 有什么问题。

我还没有开始使用模拟框架,我还没有开始感受到不使用它的痛苦。

我是否会在某个时候受伤,having chosen handwritten stubs and fakes instead of mocks (like Rhinomock etc)? (使用福勒分类法)

在模拟 stub 和手写 stub 之间进行选择有哪些注意事项?

最佳答案

stub 没有任何问题, stub 、模拟......和 spy 有空间。都是“测试替身”,但用途不同,如 Mocks and Stubs aren't Spies 中所述:

[...] Before moving on, I'd like to clarify and define some terms in use here, which I originally discovered in Gerard Meszaros' xUnit Patterns book.

  • A Dummy Object is a placeholder object passed to the system under test but never used.
  • A Test Stub provides the system under test with indirect input
  • A Test Spy provides a way to verify that the system under test performed the correct indirect output
  • A Mock Object provides the system under test with both indirect input and a way to verify indirect output

[...] And you can let this handy chart guide your decisions:

alt text



PS: Mockito - The New Mock Framework on the Block也值得一读。

关于unit-testing - 用于单元测试的 stub 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1522846/

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