I write tests
alongside the code. I also write tests before the code,
and after the code.
Usually, I use test harnesses[0]. These generally start before the code, and grow, alongside.
I’ll frequently write unit tests, after the code is done. Sort of like putting solder over a tightened bolt.
But I tend to spend a lot of time and effort on testing. It’s my experience, that I always find issues. I’ve never once, written “perfect” code, out of the starting gate.
Eh. WFM. YMMV.
IRT the post topic, I believe that every job I do -even “farting around” code- needs to be done as well as possible. If I always do a good job, then it becomes habit.
[0] https://littlegreenviper.com/testing-harness-vs-unit/