神刀安全网

NET Mocking Frameworks, a comparison

Working in a TDD environment brings up one of the most important situations you need to consider. Choosing a good mocking framework like most things in development is important decision for your current development situation. Today i look at a few of the factors to consider when choosing common frameworks along with a breakdown of the features that they have to offer.

It is generally a good idea to pick and active and popular framework, something that has a large community of support. Personally i prefer open source frameworks over commercial however this is generally down to the developer/team. [ Largest community: Moq ]

One of the more important features you should focus on is its speed. Tools that use CLR profiling are generally slower so one thing you need to take into consideration is the quantity of unit tests that you expect. [ Fastest: Moq ]

Ease of use is always an important factor to consider if you are choosing a framework for a larger development team. Complicated frameworks don’t mean that they are the best frameworks. Sometimes keeping things simple and straightforward can be the best decision you can make. For example if using MOQ make sure you and all your developers are efficient in using lambda expressions. [ Simplest: xUnit ]

Are there any integration issues with other chosen components? For instance, does it work with the desired .NET framework version.

Maybe something else you could look into is who the creators are. Are they teams or an individual developer and ontop of that check out how often releases are made. An active framework is much more likely fulfill your needs. [ Very active: Moq | Not so active: TrueFakes]

If you really want to dig into each framework further then the ideal situation would be to create a project that does something hefty and then write multiple test for it to determine the performance.

Common Frameworks

Justmock lite- github.com/telerik/JustMockLite The most powerful free mocking library available for .NET developers.

NSubstitude- nsubstitute.github.com/   –  NSubstitute is a friendly substitute for .NET mocking frameworks. It has a simple, succinct syntax to help developers write clearer tests. NSubstitute is designed for Arrange-Act-Assert (AAA) testing and with Test Driven Development (TDD) in mind.

Rhino Mocks- github.com/meisinger/rhino-mocks –  Dynamic mocking framework for .NET

Moq- www.moqthis.com/ –  Moq is the most popular and friendly mocking framework for .NET

FakeItEasy- fakeiteasy.github.io/ –  It’s faking amazing! The easy mocking framework for .NET that works great in C# and VB.NET alike. No need to know the difference between a stub, a mock or a spy, everything’s a fake! The easy to use, refactoring friendly API makes faking a breeze.

NMock3- nmock3.codeplex.com/ –  NMock3 is a Mocking framework that uses lambda syntax to set-up expectations and test interactions between classes and interfaces.

True Fakes- nuget.org/packages/TrueFakes/ –  Xamarin based mocking framework that really helps to isolate dependencies in your mobile unit tests.

JustFakeIt- github.com/justeat/justfakeit –  An In Process HTTP server which can be mocked and asserted against to allow for full stack HTTP testing.

FOQ- foq.codeplex.com/ –  Foq is a lightweight thread-safe mocking library for F#, C#, and VB with a similar API to Moq.

Comparison

2016-05-36

Framework

Free?

Source Code Available

Dependencies

Nuget Package

Documentation

Downloads

Telerik Justmock lite

Yes

Yes

No

Yes

Yes

61,179

NSubstitute

Yes

Yes

No

Yes

Yes

938,799

Rhino Mocks

Yes

Yes

No

Yes

Yes

625,455

Moq

Yes

Yes

No

Yes

Yes

6,004,850

FakeItEasy

Yes

Yes

No

Yes

Yes

393,026

NMock3

Yes

Yes

No

Yes

No

13,827

True Fakes

Yes

No

No

Yes

No

818

JustFakeIt

Yes

Yes

Yes (3)

Yes

No

12,338

FOQ

Yes

Yes

No

Yes

No

16,887

References:

http://www.coderewind.com/2014/07/top-5-mocking-frameworks-net-developers/

http://graemef.com/blog/2011/02/10/A-quick-comparison-of-some-.NET-mocking-frameworks/

http://nugetmusthaves.com/Tag/mocking

https://www.nuget.org

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » NET Mocking Frameworks, a comparison

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址