More weird tests
It has been a while since I wrote about weird tests. This is not due to lack of enthusiasm — if anything, I think my passion for them has redoubled over the past eighteen months.
The construct and appeal of programmatically declaring invariants about your codebase and gating CI on them is, for reasons that hopefully do not require elaboration, more appealing than ever. Here are a handful that I've grown fond of:
- A test to make sure that every single partial and SVG in your codebase is imported at least once. knip is a great tool for this in the JavaScript ecosystem, but it turns out that there are other ecosystems as well.
- A test to make sure that every new model has at most one status field.
- A test for making sure that the current commit has at most one migration.
- A test for ensuring that all migrations have a reverse operation associated with them.
- A test to make sure every localization string is meaningfully different — not just different due to punctuation or pluralization.
- A test to make sure
example.comis never used as, well, an example.
In much the same way I use regression tests as a no-nonsense way to grow a conventional test suite — if something's broken, add a test and then fix it — I've started using weird tests as regressions for things that I feel silly flagging in code review or catching in prod. It's a useful tool, and I'm happy I've developed the muscle memory to reach for it.