Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I want to do Unit test for my project.For this purpose I need to create a mock object?
I do not know how to create it. Please help me to create it.
Posted
Comments
♥…ЯҠ…♥ 23-Nov-13 5:36am    
what mock framework you are using for unit testing?

1 solution

If you want to use RahnoMock (Mocking framework) then you can create as follows

C#
static void Main(string[] args)
{        
   var logger = Rhino.Mocks.MockRepository.GenerateStub<ILogger>();
   logger.Log("hello");
}
public interface  ILogger
    {
        void Log(string data);
    }
</ilogger>

Note: You need to take a reference of Rhino.Mocks.dll assembly.

More details: http://hibernatingrhinos.com/oss/rhino-mocks[^]
 
Share this answer
 
v2
Comments
Tanumay99 25-Nov-13 3:30am    
Thank you.
Please help me for more details about this
S. M. Ahasan Habib 25-Nov-13 4:03am    
You need to follow some steps to create mock object
step1> Download rahno mock dll from the above link (which i provide in solution section)
step2> Add that Rhino.Mocks.dll to your .net test project
step3> where you need to create mock object you use GenereteStub<t> method of MockRepository class. It will create mock object for you.
step4> Inject that mock object to your test class.

The article may help you
http://www.codeproject.com/Articles/686935/Unit-testing-with-Mock-objects-Rhino-Mocks
Tanumay99 25-Nov-13 5:40am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900