3 ms·
>Don't try to write the tests first, that's a productivity anti-pattern. Uh, this isnt great advice. If you're spiking then sure, dont write a test at all. I
by pydry 2y ago
>Don't try to write the tests first, that's a productivity anti-pattern.
Uh, this isnt great advice.
If you're spiking then sure, dont write a test at all.
If you're writing production code you should have a clear picture of what it should do before you start. Your test should validate that so it makes sense to write that next. It serves as a natural transition from your requirement to youe code.
Ive written a lot of code without tests at all for good reasons and a lot of tests before code but ive never witnessed a good reason to write a test after writing the code. At best it is almost as beneficial.
- simonw 2y agoI stand by what I said. It's unconventional advice and goes against industry "best practice" - plenty of people will imply that if you're not writing your tests before your implementation you're "doing it wrong". I think that advice causes people to skip writing tests entirely and feel guilty about it, because often writing test first really does slow down your development process substantially in many cases. My experience is that writing tests after the implementation gives me all of the value of writing the test before but takes genuinely about half the amount of time. You can't do snapshot testing if you force yourself to write the tests first!
- pydry 2y ago>I think that advice causes people to skip writing tests entirely and feel guilty about it I dont think guilt or lack thereof is a good rationale for any development practice. It actually annoys me that people so often add a moral dimension to development practices. The only question that matters is "does it work well?" >You can't do snapshot testing if you force yourself to write the tests first! Yes you can you can write the whole test, you just cant lock the snapshot artefact(s) in until you've written the code.