Looking for advice on writing and maintaining a good unit test suite. I’ve been following the guidance given in Life of a File on how to grow my codebase, but that leaves me wondering how best to approach unit tests in a disciplined manner. I’ve tried just writing them to exercise the code I’ve already written (so like development driven testing), but I often find that it’s hard to maintain them with all the big refactors that seem so common.
To be more specific, here are a few pain points I’ve noticed:
- I find it really hard to pull out good data structures that will stay stable enough to build modules and tests around.
- The compiler is already checking so much that my tests often feel redundant or unnecessary.
- The Elm runtime does something that I can’t stub or mock. E.g. https://github.com/elm-explorations/test/issues/24
- The little helper functions that are easy to test aren’t exposed by my modules, so my tests can’t access them.
For now I’ve just been focusing on keeping my integration tests up to date using Cypress, and not worrying so much about unit tests but I miss having the feedback loop you get from a good unit test suite.
Has anyone had success growing a unit test suite alongside their codebase? How did you make it worth the extra time and effort? Any tips or examples I could look at? Thanks!