Are fakes better than mocks?

I stumbled upon this open source project Fake It Easy and I have to admit it looks very interesting, however I have doubts what is the difference between FIE fakes and say Moq Mocks? Is anyone better suited for specific purposes?

EDIT:

What is this new structure that will make it better than saying Moq?

+48
c # unit-testing mocking fakeiteasy
Oct 22 '10 at 21:28
source share
4 answers

To be clear, I created FakeItEasy, so I definitely won't say if one environment is better than another, what I can do is point out some differences and motivate why I created FakeItEasy. Functionally, there are no significant differences between Moq and FakeItEasy.

FakeItEasy does not have “Confirmed” or “Expectations”, however it does have statements, they are always clearly indicated at the very end of the test, I believe that this makes reading and understanding tests easier. It also helps beginners avoid multiple statements (where they will set expectations in many calls or mock objects).

I used to use Rhino Mocks, and I really liked it, especially after the AAA syntax was introduced. However, I liked the free Moq API. What I didn’t like with Moq was the “mock object”, where you should use mock.Object everywhere, I like the Rhino approach with the “natural” poppies better. Each instance looks and looks like a normal instance of a fake type. I wanted the best of both worlds, and also wanted to see what I can do with the syntax when I had absolutely free hands. Personally, I (obviously) think that I have created something good that blends in with the best of the world, but it's pretty easy when you stand on the shoulders of giants.

As already mentioned, one of the main differences is the terminology, FakeItEasy was first created to introduce TDD and mock newbies and worry about the differences between mocks and stubs in the front (as you would need in Rhino), in my opinion not very helpful.

I pay great attention to exception messages, it should be very easy to say what was once wrong in the test, just looking at the exception message.

FakeItEasy has some extensibility functions that other structures do not have, but they are not very well documented yet.

FakeItEasy (hopefully) is a little stronger in mocking classes that have constructor arguments, since it has a mechanism for determining which dummy values ​​to use. You can even specify your own dummy value definitions by embedding the DummyDefinition (Of T) class in your test project, this will be automatically picked up by FakeItEasy.

The syntax is the obvious difference, which best of all depends on the taste.

I am sure that there are many other differences that I forgot about now (and, to be honest, I never used Moq in production, so my knowledge about this is limited), I think these are the most important differences, though.

+85
Nov 13 '10 at 20:20
source share

The terminology used in testing can be a bit confusing. The best source explaining the difference between different concepts is Mocks Are not Stubs by Martin Fowler. Thus, fake is a general term that describes both stubs and layouts.

+23
Oct 22 2018-10-22
source share

Taunted terminology can be confusing - and sometimes completely unintuitive.

Therefore, many people have proposed a simpler new terminology where you only have fakes , mocks and stubs .

Fake is a general term for all possible types of double tests, regardless of where they come from or how they are used.

In addition, fakes differ only in one dimension: do they affect the test result or not; or, in other words: whether it is necessary to set the return values ​​for a fake, which are used in some way during the test execution, or is it a "quiet" object that serves only to perform some kind of dependency.

Stub is a silent object.

Mock is actively involved in the test.

In addition, there is no other difference, which undoubtedly has its historical merits, but at the present time is largely contrary to intuition and academicity, and this is a kind of confusion of really important concepts of development caused by tests.

Regarding the comparison between Moq and FakeItEasy : the two frameworks are basically the same from a conceptual point of view - differences exist only in the API and in terminology ...

Thomas

+9
Oct 23 '10 at 4:59
source share

From my point of view, Fake does not cancel Moc, for example, I use Dev Magic Fake to fake DAL and Business level and at the same time I use Mock in MVC for HTTPContext

var repoistory = new FakeRepository<ProductTypeForm, VendorForm>(); repoistory.Save(productTypeForm); this.FillDropDown(new FakeRepository<VendorForm>()); 

In the previous code, Dev Magic Fake will save ProductTypeForm and retrieve VendorForm from Dev Magic Fake and associate it with ProductTypeForm, this save operation may be permanent

For more information about Dev Magic Fake, see it at CodePlex: http://devmagicfake.codeplex.com

They check this method, which we need to iterate over the HTTP context.

 var context = new Mock<HttpContextBase>(); var request = new Mock<HttpRequestBase>(); 

So I work with fake and layout

-one
Sep 06 '11 at 12:44
source share



All Articles