Ask HN: Do you write tests before the implementation?
91–100 of 329 posts
Re: Ask HN: Do you write tests before the implementation?
#92Then as the project evolves, I start adding more high level tests to avoid regressions.
I prefer high level testing of products, they're more useful since you can use them for monitoring as well, if you do it right. I work with typed languages so there's little value in unit tests in most cases.
Sometimes I'll write a test suite "first", but then again only once I have at least written up a client to exercise the system. Which implies I probably decided to stabilize the API at that point.
Like others have said, tests often turn into a huge burden when you're trying to iterate on designs, so early tests tend to cause worse designs in my opinion, since they discourage architectural iterations.
Re: Ask HN: Do you write tests before the implementation?
#93Earlier quoted context omitted.
> Committing the red test and the fix to the test in two commits makes the bug and its fix easy to review. I've done this in the past. Then I started to use `git bisect` and having a red test somewhere in your commit-history is a killer for bisect. So now I tend to include both, the test and the bug-fix, within one commit.
A tip I learned is to commit the failing test but mark it as an expected failure, if your test framework supports that. That way you can commit the test, bisect works, and the test begins "failing" when the bug is really fixed, and you can commit the fix as well as a one-line change to amend the test from being failure-expected to just a normal test.
Re: Ask HN: Do you write tests before the implementation?
#94Re: Ask HN: Do you write tests before the implementation?
#95Most of programming happens in the exploration phase. That's the real problem solving. You're just trying things and seeing if some api gives you what you want or works as you might expect. You have no idea which functions to call or what classes to use, etc.
If you write the tests before you do the exploration, you're saying you know what you're going to find in that exploration.
Nobody knows the future. You can waste a crazy amount of time pretending you do.
Re: Ask HN: Do you write tests before the implementation?
#96Yeah. 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.
Re: Ask HN: Do you write tests before the implementation?
#97In new code, I'll usually write high level black box tests once enough code is in place to start doing something useful. I rarely write unit tests except for behavior that is prone to be badly implemented/refactored, or for stuff that's pretty well isolated and that I know I won't touch for a while. Then as the project evolves, I start adding more high level tests to avoid regressions. I prefer high level testing of…
Re: Ask HN: Do you write tests before the implementation?
#98Nope. I pretty much always find it to be counterproductive. Most of programming happens in the exploration phase. That's the real problem solving. You're just trying things and seeing if some api gives you what you want or works as you might expect. You have no idea which functions to call or what classes to use, etc. If you write the tests before you do the exploration, you're saying you know what you're going to fi…
Write a POC to learn then you can write tests first for production.
Re: Ask HN: Do you write tests before the implementation?
#99Re: Ask HN: Do you write tests before the implementation?
#100In new code, I'll usually write high level black box tests once enough code is in place to start doing something useful. I rarely write unit tests except for behavior that is prone to be badly implemented/refactored, or for stuff that's pretty well isolated and that I know I won't touch for a while. Then as the project evolves, I start adding more high level tests to avoid regressions. I prefer high level testing of…
Unit tests actually are the most important ones... I do not wanna work on any of your projects heh.
It really depends on the situation. There is no silver bullet when it comes to testing.