Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between MOQ and AutoFixture?

I have a fair amount of experience using MOQ, while I've recently have stumbled into AutoFixture. What are the differences between these frameworks?

like image 374
Carlo V. Dango Avatar asked Apr 26 '11 06:04

Carlo V. Dango


People also ask

What is AutoMoqCustomization?

The AutoMoqCustomization is the core of the integration of AutoFixture with Moq. By adding an instance of this class to the fixture, requests for non-concrete types will be handled by Moq. var fixture = new Fixture(); fixture.

What is AutoFixture C#?

AutoFixture is an open source library for . NET designed to minimize the 'Arrange' phase of your unit tests in order to maximize maintainability.

What is AutoFixture Xunit?

AutoFixture is a tool designed to make Test-Driven Development more productive and unit tests more refactoring-safe.

What is Moq mock?

Moq is a mocking framework built to facilitate the testing of components with dependencies. As shown earlier, dealing with dependencies could be cumbersome because it requires the creation of test doubles like fakes. Moq makes the creation of fakes redundant by using dynamically generated types.


1 Answers

The FAQ explains the difference. In short

AutoFixture uses Reflection to create 'well-behaved' instances of public types. It auto-generates instances of other types if necessary to fill in arguments for a constructor, and also assigns values to public writable properties. In essence, it simply uses the requested type's public API to instantiate and populate it. It doesn't do anything that you, as a developer, couldn't do manually - it just does it for you automatically.

In contrast, most Dynamic Mock libraries derive from known types to override the behavior of virtual members. Their purpose is to perform Behavior Verification of the System Under Test (SUT).

You can combine AutoFixture with Moq to turn it into an automocking container.

like image 153
Mark Seemann Avatar answered Oct 05 '22 19:10

Mark Seemann