Yeah. I also floss every day, clean up the kitchen as I cook, keep off-site backups of my personal data, call my mother regularly to thank her for raising me, read the terms and conditions to online services, keep an up-to-date to-do list, and change all my passwords once a month.
Ask HN: Do you write tests before the implementation?
121–130 of 329 posts
Re: Ask HN: Do you write tests before the implementation?
#122Re: Ask HN: Do you write tests before the implementation?
#123Earlier quoted context omitted.
I would agree that "coverage gives an idea of how many lines of code have been run, but obviously no guarantees of correctness for those specific lines"
Perhaps I should rephrase. If you're trying to effectively unit test a project, when do you decide you've tested enough? And are there any metrics which help support that? Coverage for example is a weak signal that you've at least run some fraction of your codebase at test time.
Re: Ask HN: Do you write tests before the implementation?
#124- The uncomfortable truth for some is that not doing any testing at all can be a perfectly fine trade off and there's plenty of successful projects that do this.
- Sometimes the statically checked assertions from a strongly typed language are enough.
- Sometimes just integration tests are enough and unit tests aren't likely to catch many bugs.
- For others, going all the way to formal verification makes sense. This has several orders of magnitude higher correctness guarantees along with enormous time costs compared to TDD.
For example, the Linux kernel doesn't use exhaustive unit tests (as far as I know) let alone TDD, and the seL4 kernel has been formally verified, both having been successful in doing what they set out to do.
I notice nobody ever gets looked down on for not going the formal verification route - people need to acknowledge that automated testing takes time and that time could be spent on something else, so you have to weigh up the benefits. Exhaustive tests aren't free especially when you know for your specific project you're unlikely to reap much in the way of benefits long term and you have limited resources.
For example, you're probably (depending on the project) not going to benefit from exhaustive tests for an MVP when you're a solo developer, can keep most of the codebase in your head, the impact of live bugs isn't high, the chance of you building on the code later isn't high and you're likely to drastically change the architecture later.
Are there any statistics on how many developers use TDD? There's a lot of "no" answers in this thread but obviously that's anecdotal.
Re: Ask HN: Do you write tests before the implementation?
#125Earlier quoted context omitted.
To each their own. I have seen many times all the unit tests pass, but the application is broken. It really depends on the situation. There is no silver bullet when it comes to testing.
Yeah that's why "every" open source project you trust has a shitload of unit test. For amateurs, no tests, pros write test always.
Re: Ask HN: Do you write tests before the implementation?
#126So, in short, I view tests as a super useful, but over-applied tool. I want my tests to deliver high enough value to warrant their ongoing maintenance and costs. That means I don't write nearly as many tests as I used to (in my own projects), and far fewer than my peers.
Where I work, tests are practically mandated for everything, and a full CI run takes hours, even when distributed across 20 machines. Anecdotally, I've worked for companies that test super heavily, and I've worked for companies that had no automated tests at all. (They tested manually before releases.) The ratio of production issues across all of my jobs is roughly flat.
This issue tends to trigger people. It's like religion or global warming or any other hot-button issue. It would be interesting to try to come up with some statistical analysis of the costs / benefit of automated tests.
Re: Ask HN: Do you write tests before the implementation?
#127Re: Ask HN: Do you write tests before the implementation?
#128Never done this, and don't consider it practical. Code and interfaces (even internal ones) change rapidly for me when I'm starting a new project or adding new major functionality to the point that the tests I'd write at the beginning would become useless pretty quickly. I also believe that 100% test coverage (or numbers close to that) just isn't a useful goal, and is counterproductive from a maintenance perspective:…
Often people fall back on manual testing, which is often slow, unreliable and incomplete. And certain things might not even be testable if the system hasn't been designed to allow it.
Re: Ask HN: Do you write tests before the implementation?
#129Re: Ask HN: Do you write tests before the implementation?
#130I can't even code like that except maybe for simple tasks in a mature project. I'm more a "Make It Work, Make It Beautiful, Make It Fast" person and don't see it working by writing unit test first.