Hacker News new | ask | show | jobs
by ttoinou 21 days ago
There is a whole religion about tests that is worth attacking though
2 comments

Sure. If his take was "100% unit test coverage is a waste of time" I think that's not unreasonable. You could make a case that the "you must write tests before you write code, every single time!" stuff is needlessly dogmatic. I also think that sometimes people focus too much on unit tests to the detriment of end to end tests that better model actual system interactions.

None of these were Theo's take. He was pushing the idea that unit tests in general were a waste of time because you could be shipping new features instead.

https://www.youtube.com/watch?v=pvBHyip4peo for an example of this. The nicest possible interpretation on this is that he's deliberately saying something he knows is wrong to attract attention.

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.

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
He doesn't believe that unit tests are complete waste of time. Just a relative waste of time. He doesn't mind AI agents writing tests. It's just mostly waste of time for humans. Because the value you get for them is not worth developer time in most cases. It's worth agent time.
When I start using a chainsaw or a car I hope it has been tested (!) Without tests before delivery the one who tests is the end user. Disaster for a unreliable chainsaw, very unpleasant for a software.

But you're right, the goal is not to write test but to ensure delivery of a reliable software. However each software is a prototype, something that has never been made before (unlike a manufactured car or chainsaw) so the customer must be ready to some unexpected behaviors when the software is released.

Since tests are often sloppy or does not cover every edge case, I see a real value for GenAI. It also forces to write good spec: very clear about inputs and the invariants for each use case. I think that AI (especially GenAI) should first be a solution to existing problem, lack of tests and good specs is often one of them.

If you write too many preconditions, postconditions, invariants etc. Then you cement your software and you will spend most of your time on the tests rather than on the actual useful software