A fake is a generic term that can be used to describe either a stubor a mock object (handwritten or otherwise), because they both look like thereal object.
Whether a fake is a stub or a mock depends on how it’s used inthe current test. If it’s used to check an interaction (asserted against), it’s amock object. Otherwise, it’s a stub.
Fakes makes sure test runs smoothly. It means that reader of your future test will understand what will be the behavior of the fake object, without needing to read its source code (without needing to depend on external resource).
What does test run smoothly mean?
Forexample in below code:
public void Analyze(string filename) { if(filename.Length<8) { try { errorService.LogError("long file entered named:"+ filename); } catch (Exception e) { mailService.SendEMail("admin@hotmail.com", "ErrorOnWebService", "someerror"); } } }
You want to test mailService.SendEMail() method, to do that you need to simulate an Exception in you test method, so you just need to create a Fake Stub errorService class to simulate that result, then your test code will be able to test mailService.SendEMail() method. As you see you need to simulate a result which is from an another External Dependency ErrorService class.