删除“集成测试骗局” - 了解协作和合同测试

发布于 2025-01-04 23:59:49 字数 746 浏览 5 评论 0原文

我最近观看了 JB Rainsberger 的集成测试是一个骗局,现在正在寻找有关该主题的更多材料。我不得不说,我对我们做错了多少事感到震惊(即,当我们应该进行单元测试时却进行了集成测试),我对 Rainsberger 描述的概念很感兴趣,但也对如何应用它们感到困惑。我想要更多所描述的协作测试和合同测试,但我不知道从哪里开始。

唯一困扰我的是测试需要提出的 4 个问题:

A 方:

Do I ask the right question?
Can I deal with the answer?

B 方:

Can I answer a question?
Do I answer correctly?

但是我如何将其应用到某些随机方法中我的应用程序堆栈?

是否有书籍、教程或示例采用现实世界的示例并应用这些孤立的微观测试的想法? 理想情况下,该示例使用 Java、C# 或 C++。

任何涉及这些概念并帮助我更好地理解它们的文献都将受到赞赏。

另外,如果有论坛,我可以询问有关如何正确进行单元测试的更详细的问题,甚至重构现有代码并发布示例,那就太好了。

谢谢!

I've recently watched Integration Tests are a Scam by J. B. Rainsberger and am now looking for more material on the subject. I have to say, I'm shocked by how much we're doing wrong, (i.e. integration testing when we should unit test), intrigued by the concepts described by Rainsberger but also confused about how to apply them. I would like to have more of the described collaboration tests and contract tests but I don't know where to start.

The only things that got stuck in my mind are the 4 questions the tests need to ask:

Side A:

Do I ask the right question?
Can I deal with the answer?

Side B:

Can I answer a question?
Do I answer correctly?

But how do I apply this to some random method in my application stack?

Is there a book or a tutorial or example out there that takes a real world example and applies these ideas of isolated micro tests?
Ideally the example uses Java, C# or C++.

Any literature that deals with these concepts in general and helps me understand them better would be appreciated.

Also if there are forums out there where I can ask more detailed questions about how to go about correctly unit testing and maybe even refactoring existing code and post examples would be nice.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怎樣才叫好 2025-01-11 23:59:49

我会推荐 xUnitTestPatterns - Gerald Meszaros 的重构测试代码,它提供了对您的问题的一些见解以及有关良好和良好的详细信息。在单个方法级别进行测试时,各种做法都不好。

如果您读过福勒的《重构》,您会发现您的问题的答案不一定是黑白分明的,而是基于您和其他人的经验的启发。

I would recommend xUnitTestPatterns - Refactoring Test Code by Gerald Meszaros which provides some insights into your questions and a lot of detail on good and bad of various practices when testing at the individual method level.

If you have read Refactoring by Fowler, you'll see that the answer to your questions is not necessarily black and white, but based on heuristics from your and others experience.

子栖 2025-01-11 23:59:49

Rainsberger 过分夸大了集成测试的低效程度,以证明他的观点是在代码中达到最终 100% 质量(基本正确性)。DbC

专注于形式化 A 方和 B 方之外的责任和利益。就像一个接口的扩展。因此,主要焦点变成了合同本身,中间的一层可以告诉双方是否可以相互交互。

Rainsberger 明确表示,到目前为止,还没有明确的库或语言支持,并且可以同时实现 A 模拟和 B 输入来询问同一件事,暗示这可能是某人的博士工作。

然而 Jim Weirich 有一个很好的例子,其中契约是一种用于测试和同意使用它的双方的 OO 模式
https://www.youtube.com/watch?v=7Yw744FMqTY

Rainsberger over-exaggerates how inefficient integration testing is, to prove his point in reaching ultimate 100% quality (basic correctness) in code

DbC is focused on formalizing responsibilities and benefits outside of both A and B parties. Is like an extension of interface. So main focus becomes contract itself, a layer in the middle that would tell both parties if they can interact with one another.

Rainsberger clearly says that so far there is no explicit library or language support and achieve both A mocks and B inputs to ask same thing, hinting that it could be a PhD work for someone.

However Jim Weirich has a nice example where contract is a OO-pattern for testing and for both parties that agree to use it
https://www.youtube.com/watch?v=7Yw744FMqTY

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文