Iâm a frontend developer. All the meaningful tests always break for the stupidest, obscure reasons. Thatâs why I donât write tests.
Hereâs my take. In order to be able to write meaningful unit tests the code should be structured in a certain way, with very modular, decoupled units, dependency injection, favoring composition and polymorphism over inheritance and so on.
If you manage to write your code this way it will be an objective advantage that will benefit the project even if you donât write a single unit test. But it does make unit tests much easier to write, so presumably youâll end up with more tests than otherwise.
IMO teams should prioritize this way of writing code over high test coverage of non-modular code. Unit tests for deeply-coupled code are a nightmare to write and maintain and are usually mostly meaningless too.
One rule of thumb Iâve heard and follow is that every time you encounter a bug, you write a unit test that would catch it. I find that does a pretty good job of getting high code coverage, though maybe thatâs cause my code is naturally buggy đ .
All you folks are crazy not to unit test personal projects. Unit tests donât need to be fancy and exhaustive. A sanity check and having a simple way to execute isolated code is well worth the 15 minutes of setting it up. Heck, just use them as scratch files to try out libraries and APIs. I canât imagine having the kind of time to raw-dog that f12 button and sifting through print() nonsense all night.
I think it also very much depends on your tooling & how easy it feels to start writing unit tests.
When I work in a Java project for example I always write unit tests even for personal stuff, because the IDE integration is great and itâs really quick to create a test class, run it and see granular results. I donât feel the same way about testing JavaScript because the tooling at least for me hasnât worked quite as well (though that could very well be my own fault, itâs been a while since I looked into it). The more cumbersome setting up and running the tests is, the more tempting it becomes to just use the console or manually test parts instead.