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.

Ask HN: How do you come up with a set of test cases for your code?

12 pointsby gashawover 6 years ago
I'm interested to know what methods software developers and testers are using in practice. How confident are you in your tests?

3 comments

tcbascheover 6 years ago
- If it&#x27;s a straight-forward pure function, I tend to use Hypothesis[1] to pile in random inputs. It&#x27;s a great tool for coming up with cases humans wouldn&#x27;t normally think of (I also wrote a blog post about this [2])<p>- If there was a show-stopping bug in production, I like to go back and write a test that covers that case (even if it was fixed).<p>- However in most cases, I cover off the typical use cases and I find, as another commenter says, it&#x27;s &quot;good enough&quot;.<p>[1] <a href="https:&#x2F;&#x2F;hypothesis.readthedocs.io&#x2F;en&#x2F;latest&#x2F;" rel="nofollow">https:&#x2F;&#x2F;hypothesis.readthedocs.io&#x2F;en&#x2F;latest&#x2F;</a> [2] <a href="https:&#x2F;&#x2F;medium.com&#x2F;@thomas.basche&#x2F;testing-with-hypothesis-26cd2b1a72fe" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;@thomas.basche&#x2F;testing-with-hypothesis-26...</a>
mrburtonover 6 years ago
This is exactly what TDD came about. It was designed to help you a) write code that you need and b) tests that validate the code does what it&#x27;s suppose to do.<p>In terms of the latter, you can boil it down to two aspects.<p>a) Does the code function correctly given positive input? b) Does the code fail in a deterministic manner? e.g., if an age is a negative number, does it&#x27; throw an appropriate error message?<p>In the failure case, it can get more trickier when you start to introduce things like database persistence or API calls. In this case, you should mock out these dependencies and also set up scenarios to make sure your code also fails in a deterministic manner.<p>Keep in mind, what&#x27;s really important is to make sure your code only doesn&#x27;t what&#x27;s required and nothing more. Keep things simple and no simpler. ;)
viraptorover 6 years ago
Usually it&#x27;s two groups: 1. regular usage as seen now or expected in the future, 2. exercising all existing error paths. I&#x27;m pretty confident that it&#x27;s both a reasonable coverage and that there are going to be some missed patterns. It&#x27;s &quot;good enough&quot;
评论 #19124882 未加载
评论 #19125719 未加载