Testing

Top 5 Mocking Frameworks for .Net Developers

When you are planning to perform data driven unit test for any large scale application, it is very difficult to manage and speed up the task due to vast interaction of the application with its databases, services, etc. Unit testing for these kinds of large applications can be performed manually but it will be very time consuming and will involve lots of money. So, here the concept and role of mock or mocking framework comes useful.

So, what does mock mean? Mock means that you are planning to test a process without its actual data input with some other replacement mock/dummy/fake data as an input.

Mocking is mainly used in unit testing. Mocking is creating fake objects or creating objects that simulate the behavior of real objects. With mocking, you can test your own separate code and you don’t need to wait for another team member code to be finished. There are three replacement objects that are used to replace dependencies of the unit being tested and these are – stubs, fakes and mocks.

What is a Mocking Framework?
Mocking framework is used to create replacement objects like Fakes, Stubs and Mocks. It is used to isolate each dependency and help developers in performing unit testing in a concise, quick and reliable way.

Creating mock objects manually is difficult and time consuming so to increase your productivity you can go for automatic generating of mock objects by using a mocking framework. A developer can build his/her unit test by using any of one NUnit, MbUnit, MSTest, xUnit etc. unit test framework and can further test it on a mocking framework.

Here Comes Our List of Top 5 Mocking Frameworks for .Net Developers:

1) NSubstitute
mocking framework
image credit: http://nsubstitute.github.io/

NSubstitute is a free and open source mocking framework. NSubstitute creates friendly substitute for .Net mocking libraries. It is designed for Arrange-Act-Assert (AAA) testing.
License with: BSD License
Language Support: .Net
Source Code: https://github.com/nsubstitute/NSubstitute/
Latest Version: NSubstitute 1.7.2
Version History: https://www.nuget.org/packages/NSubstitute
Testing Type: Arrange-Act-Assert (AAA)
Dependencies: This package has no dependencies.
Download NSubstitute

2) Rhino Mocks
mocking framework

Rhino Mocks is open source and dynamic mocking framework for .Net web applications. It is written by Ayende Rahien and ensures that you are testing the right things you want to test.
License with: BSD license
Language Support: .Net
Source Code: https://github.com/RhinoMocks/RhinoMocks
Latest Version: Rhino Mocks 4.0.0-alpha3, Rhino Mocks 3.6.1
Version History: https://www.nuget.org/packages/RhinoMocks/
Mock type: Interface or a Class with methods marked as virtual
Dependencies: This package has no dependencies.
Download Rhino Mocks

3) Moq
mocking framework

This is a popular mocking framework for .Net. This mocking framework proves to be highly helpful when you are developing a Silverlight application. Moq is a simplest mocking library for .NET and Silverlight with a nice and simple API. It is a free and open source mocking framework.
License with: BSD-2-Clause License
Language Support: .Net
Source Code: https://github.com/moq/Moq/
Latest Version: Moq 4.0.10827
Version History: https://www.nuget.org/packages/Moq/4.0.10827
Mock type: Supports mocking interfaces as well as classes.
Dependencies: This package has no dependencies.
Download Moq

4) FakeItEasy
mocking framework

FakeItEasy is an amazing and simple to use framework and is compatible with both C# and VB.Net. It provides nice options for fake and dummy creation and argument formatting. Also, it provides friendly API support.
Language Support: .Net
Source Code: https://github.com/FakeItEasy/FakeItEasy/
Latest Version: FakeItEasy 1.22.0, FakeItEasy 1.21.0
Version History: https://www.nuget.org/packages/FakeItEasy
Dependencies: This package has no dependencies.
Download FakeItEasy

5) NMock3
mocking framework

NMock3 is a popular mocking framework which uses lambda expressions. It is an open source, free and fast .Net mocking framework. It is a reliable mocking framework choice for the users.
License with: Apache License 2.0
Language Support: .Net
Source Code: http://nmock3.codeplex.com/SourceControl/latest
Latest Version: NMock3 v3.5.44
Version History: https://www.nuget.org/packages/NMock3/
Testing Type: Arrange-Act-Assert (AAA)
Dependencies: This package has no dependencies.
Download NMock3

Summary:

NSubstitute Rhino Mocks Moq FakeItEasy NMock3
Free Availability mocking framework mocking framework mocking framework mocking framework mocking framework
License With BSD License BSD License BSD-2-Clause License Apache License 2.0
Latest Version NSubstitute 1.7.2 Rhino Mocks 4.0.0-alpha3 Moq 4.0.10827 FakeItEasy 1.22.0 NMock3 v3.5.44
Source Code Availability mocking framework mocking framework mocking framework mocking framework mocking framework


Your Views
We hope that you like our list of mocking frameworks and get an insight about their useful functionalities. We have researched and then listed out these top 5 frameworks. If you know other reliable mocking frameworks for .Net developers, please feel free to share those with us and our readers in the comments section below.

If you enjoyed this post, please consider sharing, leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Web Hosting