2 ms·
Instead of relying on a mocking framework to mock the injected service, can you inject a service which implements an interface and then supply whatever type of
by 0x445442 7y ago
Instead of relying on a mocking framework to mock the injected service, can you inject a service which implements an interface and then supply whatever type of implementation you like depending on the context you'd like to test?
This is one of the neat things about Java 8 Functions. I'm not sure about what their design decisions were but effectively they backed into coding to interface vs. implementation, which used to be a solid design principle.
- LgWoodenBadger 7y agoYou could, but it’s tedious to write a new class for every scenario you want to test. Or to program for every scenario within that test implementation. And now you kind of should test your test implementation, and who wants to do that? Mocking makes it quick, easy, straightforward, and cuts out a ton of code noise from the test.