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

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.

e2

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.

e3


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
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments