chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
While looking at the provided samples I ran into Typemock.Examples.CSharp.TestB_LiveObjects . It shows that methods and properties in live objects (not faked) can also be mocked. I am wondering when should we Fake and when not.


asked by teom (2.3k points)

1 Answer

0 votes
Hi Teo,

You're asking a very good question - on one hand Isolator enables you to create fake objects (using Isolate.Fake.Instance) and on the other hand it also enables you to set expectations on live objects as if they were created as fakes. It seems as if there should be rules when to use each possibility, I guess it depends on what you're trying to achieve:

If you need to create a complicated object for your test (or object from interface or abstract class) you should create a fake object. nine out of ten times it would simplify your test.

On the other hand if creating an actual object is easier and you only need to set expectation on one or two methods use a live object seems like a better alternative (although you can use a fake object instantiated using "Members.CallOriginal").

My advice to you is write the test and see which of the two options help you create a simpler and more readable test.
answered by dhelper (11.9k points)