TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Test Isolation Is About Avoiding Mocks

78 点作者 gary_bernhardt大约 11 年前

4 条评论

hibikir大约 11 年前
Yes, we should avoid mocks of mocks. But building small pieces of code that have little knowledge of their surroundings, and testing them independently, is no panacea.<p>You can see this problem in any Java Enterprise shop that has code coverage as a religion: To make it possible to cover all that code (including all the boilerplate caused by the technologies selected), then we end up with a billion little classes that are managed by some kind of dependency injection system. Hundreds of thousands of lines of Spring XML configuration files, or their equivalent in annotations. Every piece is tested, but are all the pieces tested together, automatically? We quickly get into extremely large and expensive automation suites, or a whole lot of things that aren&#x27;t really tested regularly, making all those unit tests a lot less valuable.<p>We can&#x27;t wish complexity away: Make every unit too small, and the management of the units is now your new problem. You head in the same direction with the whole Microservices context.<p>A maintainable system is one built of components that are just simple and cohesive enough to be understandable by a human, but not any simpler. The right modularization is the hardest thing we do in software. The right size is hard to gauge, modules like that might be hard to name, and they are often hard to test. Sometimes one of those aspects must suffer for the others to do well.
评论 #7752234 未加载
评论 #7752582 未加载
henrik_w大约 11 年前
Reducing the knowledge of internal structures is what the Law of Demeter (<a href="http://en.wikipedia.org/wiki/Law_of_Demeter" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Law_of_Demeter</a>) is about. Usually good practice.
评论 #7752118 未加载
adamors大约 11 年前
Well, one thing I learned from all this recent TDD related discussion is that almost nobody is aware of this book [1] and the entire school of TDD it spawned.<p>[1] <a href="http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627" rel="nofollow">http:&#x2F;&#x2F;www.amazon.com&#x2F;Growing-Object-Oriented-Software-Guide...</a>
评论 #7751964 未加载
评论 #7751928 未加载
vinceguidry大约 11 年前
I&#x27;m just happy Gary&#x27;s gracing us with his wisdom semi-regularly again.