TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Tests Should be Specific [video]

55 pointsby KentBeckover 5 years ago

7 comments

azangruover 5 years ago
I would like to hear some words of wisdom from either your guys personal experience or maybe opined by by the gurus about whether or not to use random data in unit tests.<p>On the one hand, I understand the argument that random data makes your test irreproducible; so if something breaks the test, it make take a while to figure out exactly what and why went wrong.<p>On the other hand, I feel that hard-coding test data is too restrictive. For example, in the linked video, they have a 40-hour week with a 8 dollars per hour rate, and they expect the result of the calculation to equal 320. An immediate question arises, what&#x27;s so special about these numbers? Would the test pass if the input were different? What about a 38-hour week and 20 dollars per hour? And so on...<p>What&#x27;s your take on this?
评论 #22326603 未加载
评论 #22325996 未加载
评论 #22325864 未加载
评论 #22326674 未加载
评论 #22326496 未加载
评论 #22327702 未加载
评论 #22326054 未加载
评论 #22325983 未加载
评论 #22326918 未加载
评论 #22328285 未加载
评论 #22326822 未加载
评论 #22328151 未加载
rgloverover 5 years ago
If anybody is interested, this appears to be part of a series: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=5LOdKDqdWYU&amp;list=PLlmVY7qtgT_lkbrk9iZNizp978mVzpBKl" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=5LOdKDqdWYU&amp;list=PLlmVY7qtgT...</a>
bump64over 5 years ago
Specific tests doesn&#x27;t exactly mean &quot;Simple&quot; tests. It is hard to balance between the two but from my experience when people try want to write specific tests they just start writing extremely simple tests.
cammilover 5 years ago
They seem to start talking about stacks and leaves of stacks, as if one should only test at leaves. Surely this is woefully inaccurate?<p>Isn&#x27;t the point of tests to test behaviour? Sure be specific about behaviour. And sure, unit tests should not overlap too much, but this is a separate matter to multiple tests failing, and now I don&#x27;t know where my bug is.<p>?
评论 #22326728 未加载
评论 #22326350 未加载
2rsfover 5 years ago
This is also important for system, integration, e2e or any other complex test.<p>The problem is that it is very hard to filter out failures due to environment or other unrelated issues, and even harder to pinpoint the problem
评论 #22325749 未加载
jveover 5 years ago
I rather prefer higher level tests (Integration tests?) that says, hey, you have an error. Or user will experience error. Or the expected high-level outcome is wrong.<p>Because with unit testing, I miss and can miss so much conditions. If I have high level error, sure, I will figure it out - but it is part of development process rather than something breaks live and then you have to figure that out anyway.<p>Ofcourse Unit tests have their place where I want to test that this input produces particular output (for example some parser, sanitizer class etc.) and I want to receive a signal when my future development breaks some stuff.<p>Tldr: I don&#x27;t think that having a very specific &quot;what went wrong&quot; is that important. I&#x27;m grateful when tests fail, because that saves me from mistakes going into production. It&#x27;s like a safety net.
评论 #22328463 未加载
评论 #22327763 未加载
cammilover 5 years ago
Not sure I get the point of this