Live data from Hacker News

Ask HN: Do you write tests before the implementation?

news.ycombinator.com

91–100 of 329 posts

Re: Ask HN: Do you write tests before the implementation?

#91
I fall under the category of, if I'm getting paid to do it then it's up to the client and in that case most want things done fast and cheap so testing isn't going to get done. when i'm doing open source stuff, that's for me and others to benefit and learn from, so i test EVERYTHING i can so i learn.

Re: Ask HN: Do you write tests before the implementation?

#92
In 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 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?

#93
post #21

Earlier 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.

this is why i love HN. that is such an outstanding idea.

Re: Ask HN: Do you write tests before the implementation?

#94
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.

Re: Ask HN: Do you write tests before the implementation?

#95
Nope. 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 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?

#96

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.

I see you're aiming for the sainthood too. You don't also happen to help elderly women across the road, let everyone else out at a junction and never fail to say 'please' and 'thank-you'?

Re: Ask HN: Do you write tests before the implementation?

#97

In 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.

Re: Ask HN: Do you write tests before the implementation?

#98

Nope. 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…

> Be prepared to throw one away. You will anyway.

Write a POC to learn then you can write tests first for production.

Re: Ask HN: Do you write tests before the implementation?

#99
Honestly I have to do this: Everyone who say here they don't write tests, is, an amateur. Care about your craft, write unit, integration and functional tests, before or after, rewrite them, have more than your production code, the guys that claim don't do test are the same ones who have the dumb idea to put logic in the database.

Re: Ask HN: Do you write tests before the implementation?

#100

In 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.

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.

Post reply on HN