Drinking coffee this morning, I have a personal experience while watching http://www.connexTra.com/aboutus/mockobjects.pdf.
The purpose of Mock Object is used to simulate external complex resources, so that UT can test those depends on external resources (such as databases, third-party products, etc.).
Method using Mock Object
Define a Mock Object, implement an external resource interface or define instantiate a mock object, and set State to the Mock Object Define the internal expectation value to pass this Mock Object Instance to the unit that needs to be tested. The operation is completed and the status and expectations of the Mock Object. Status comparison (Assertion)
be careful
Hard Code needs logic to avoid excessive implementation of MOCK Object should not be called each other. If this state is out, it is not necessary to complicate.
advantage
Avoid introducing Instructure Dependency premature, such as the selection of the database, from a lot of test code, the SCOPE to the Mock Object to reduce the SCOPE to the Mock Object, facilitate the discovery that can create a new Interface by Refactoring
Disadvantage
Mock Object itself is unable to avoid it because it is Unit Test, so similar to accumulation errors still requires Functional Testing