Comment

Comment by Izkata

Test-a-single-function style, what most people default to when they hear "unit test", is probably the thing that most leads into that situation.

I've been occasionally pushing coworkers to restructure code and tests into a higher level style, defining an API boundary and calling it from the rest of the code (as if you're writing a library except it's inside your codebase instead of installed), then writing tests to that API. That does make for some easily refactorable code where the tests don't need to change at all.

That pseudo-library style is kind of what "unit test" originally meant: a business unit, not a code unit. Examples simplified it too much and people copied the style instead of the substance, and the original meaning was lost.

For another example, some of our recent projects have been on updating daemons, those have also been really good candidates for this since there are clear entry and exit points.

parent Izkata 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton