I don't see this much in real world code. Is there a space/niche that does this extensively? Does it raise a bunch of arguments about anti-patterns, etc?
I don't see this much in real world code. Is there a space/niche that does this extensively? Does it raise a bunch of arguments about anti-patterns, etc?
It's unfortunate, but some languages require you to do at least some re-architecting so it's easy to test your code.
Ease of testing should absolutely affect all your production code design choices.
That said, there are terrible ways to do that, as always.
Implementing a No Op version of an interface for tests or a simple version that uses a map instead of db calles has a lot of benefits.
- it’s usually to export things which are project internal (and create references where they’re magic numbers etc otherwise) specifically to decouple tests
- otherwise it’s been basically some lighter weight version of the null wrapper
And no one has complained. Perhaps they should but I think it hasn’t been an issue because my devotion to automated testing has been more thorough and thoughtful than many of those who’d complain, and they’re happy to benefit from the safety that provides.
Honestly I think test and implementation code should be more tightly coupled not less. At least in terms of being able to reference things that are clearly project-/package-private. I know this would bother a lot of people depending on discipline, but it’s pretty much exactly what people do in many Rust projects and seems pretty successful.