I want a certain method of an object to always return a certain value when running unit tests. For example.
- Object A has Method A that normally returns “Foo”
- Object B instantiates Object A and calls Method A in Method B
- Unit Test A calls Method B
In the unit test I want Method A to return “Bar”, but in all other cases I want to return “Foo”.
I don’t think Mocking will work since you need to have the object reference ahead of time (at least with Moq). Any ideas?
Mocking is the tool to use for this kind of scenario. Most mocking framework will enable you to mock object A without creating the instance. For example moles from Microsoft will enable you to implement the scenario you describe.
Moles