A while back I asked about a feature that would allow me to use my C++ mock injection strategy in rust. The answer was that Rust doesn’t support that strategy. Since then I’ve worked out a mock injection strategy that satisfies me.
The basic idea is for classes that have dependencies to wrap around a generic parametrized with those dependencies. Testing the generic parametrized with mocks serve as tests for the class because there’s no logic in the wrapper.
I’m interested in what people here think of it. Am I mistaken in my belief that making classes testable in this way has no performance cost relative to a naive implementation? My understanding is that people who use unit tests professionally expect to have a utility that generates mocks automatically rather than hand-rolling their own the way I have for my self-teaching project. Perhaps this strategy could be meaningfully automated?