4 ms·
You don't need a "Custom test-version" of every class. If you're using dependency injection you can create a "Custom test-version" only for the things that sit
by ndr 10y ago
You don't need a "Custom test-version" of every class. If you're using dependency injection you can create a "Custom test-version" only for the things that sit at the border of your domain and use real code for everything but those.
The classic example is again storage, suppose you use Redis for storing key-value strings.
Create an interface that has the store and get method and have two implementations of that, one that actually injects a Redis client and one that injects nothing and saves everything in a map.
Now you can test the real implementation with mocks and a real Redis if you want, but all the other tests can run on the in-memory implementation just fine and super fast. No need to mock anything.
I've found mocks useful to exercise interactions (and Mockito is awesome), but once you have a fake for the types at the boundary of your dependency graph you're pretty much sorted.