Let’s say you want to UNIT test a data access layer class. But before any call is made to the data access class it calls an email class. This email component is not functional because we have still not received email server configuration details. Below is a simple code with comments depicts this situation.
So now how do we UNIT test data access layer because the email class will never allow us to execute the data access layer code. This is achieved by mocking ( by passing ) the email code.
public class Email
public bool SendEmail()
// not configured throws error
public class ClsCustomerDAL
public bool SaveRecord(string strCustomerName)
Email obj = new Email();
obj.SendEmail(); // This line throws a error
// Data acess code goes at this place but this place is never reached because // the error is throw in the previous line
Also read Can you talk about some more real time scenarios where we can use Mock testing from http://questpond.blog.com/2013/08/30/can-you-talk-about-some-more-real-time-scenarios-where-we-can-use-mock-testing/