Hacker News new | ask | show | jobs
by theshrike79 21 days ago
Tests before code makes sense when fixing bugs. Red-green specifically.

1: get bug

2: write tests that should work, but don’t because of bug

3: fix bug

4: confirm fix by running tests

Makes things a LOT easier for people checking the PR, they can just confirm the tests are correct pretty much.

As a bonus the same bug can’t surface again.

2 comments

Yep, I'm in full agreement. When extending functionality of some already existing code it also generally makes sense to write tests first.

I think the value is much lower (maybe even negative) when you're still trying to work out what shape the code will take, in an initial implementation.

Of course, as others have pointed out, nuanced opinion doesn't get clicks or YouTube views.

Oh I do that naturally as my rational problem investigation. Sometimes you can’t write a test for that, you need to test it yourself