I’d like to brush my brain to avoid confusions. In few words, what can be said about Mocking process in TDD
- What’s the GREAT idea behind MOCKING?
- Mocking frameworks are meant to be used only to avoid accessing DB during tests or they can be used for something else?
- For new comers (like me), are all the frameworks equal or I need to choose one for this or that reason?
In addition to eliminating databases and other slow or ancillary concerns from the unit being tested, mocking allows you to start writing tests for a class without having to implement any collaborating classes.
As you design some piece of functionality, you’ll realize that you need some other class or service, in order to stick to the single responsibility principle, but then you’ll have to implement those to get the first one working, which in turn will demonstrate the need for still more classes.
If you can mock or stub those dependencies, then you can create the interfaces upon which that first class will rely, without actually having to implement anything outside of that class — just return canned results from stubs of the interfaces.
This is an essential component to a test-first approach.