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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Unit Testing - Do Repeat Yourself

8 点作者 blazzerbg超过 15 年前

1 comment

gruseom超过 15 年前
I've noticed this many times, or something like it, so I also have a higher tolerance for duplication in tests than in production code. The reason is that ideally unit tests are orthogonal, self-contained little stories about the system: "when you do this, then that, X happens". There is usually a lot of overlap between the "this" and "that" addressed by different tests; indeed there had better be, or simple combinatorics suggest you're missing cases. When you try to generalize all of this to eliminate the duplication, you end up with complex, abstract code that may be shorter overall but has lost the all-important property of being able to read a given test easily and understand what it is saying about the system.<p>I just remembered I wrote about this before: <a href="http://news.ycombinator.com/item?id=239167" rel="nofollow">http://news.ycombinator.com/item?id=239167</a> (searchyc ftw).