Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A

How can we implement Mocking?

You can implement mocking by using open source mocking frameworks like Rhino mocks, MOQ etc.

For example if we want to Mock the email class method by using MOQ tool we need to write the below code. Create the email object using the Mock class of MOQ framework.


Then write the code which you want to execute rather than executing the actual code. For instance now I want to just “return true” in a hard code manner.


Now any calls to the “target” email object will always return true. At the last there is a video which talks about Mock testing.

So are we saying Microsoft does not have mock frameworks?

In Visual studio 2012 Microsoft has introduced “Fakes” which has two great features “Stubs” and “Shims” which will help us achieve mock testing.

Tags: c# fakes and shims interview questions, c# mock testing interview questions, csharp interview questions, information technology questions, programming interview questions, unit testing interview questions

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded