background preloader

Mocking

Facebook Twitter

Mocking frameworks in .Net | assumption of advancement. A few month ago I played with some mocking frameworks in .Net. There are already some comparisons available (here, here or here). In this blog post I want to show which frameworks are available and which one fits best for agile development. You could download the source code from github.com. Software under Test (SUT) To demonstrate and evaluate all the different mocking framework I had to create a scenario where it is appropriate to use a mocking framework.

This is the User entity class which implements the active record pattern. The UserGateway class is responsible to persist the entity. The validator is also more or less just a dummy for this demo. Both interfaces, IUserGateway and IUserValidator, has the same methods, properties as the classes which implement them. NMock2 One of the first mocking frameworks in .Net which I was looking at was NMock2. You could use the AAA-Syntax (Arrange-Act-Assert). But, there is are also negative points: NMock2 uses “magic strings”. NMock3 Simple.Mocking. Moq: Linq, Lambdas and Predicates applied to Mock Objects. Which Isolation(mocking) framework do you use in .NET? (Poll Closed) (poll 3746444.

.net - What C# mocking framework to use. Why do we need yet another NET mocking framework. [Updated for Moq v4 syntax] I got this question a couple times in the past MIX08 at Las Vegas. And this is a very valid question indeed, given that there’s already Rhino, EasyMock, TypeMock and NMock (to name a few). So why did we give you Moq? One possible answer would be to start with a checklist of what Moq offers that others don’t in terms of supported features. There’s one fundamental reason why there are a variety of frameworks/libraries that do similar things throughout the opensource space: more choices mean more freedom to pick the one that best suits your unique sense of style, simplicity, flexibility, etc.

The value we think Moq brings to the community is simplicity through a more natural programming model. Status-quo When I look at a Rhino Mocks quickstart and read about its "3 different record/replay syntax styles, 4 types of mocks, 7 if you include MultiMocks…", I can’t help but think that it’s far from ideal for any newcomer. Back to basics with Moq Mock Verification. Moles - Isolation framework for .NET. Pex, Automated White box Testing for .NET. The Fakes Framework in Visual Studio 2012 is the next generation of Moles & Stubs. Fakes is different from Moles, however, so moving from Moles to Fakes will require some modifications to your code. A guide for this migration will be available at a later date. Moles will not be developed further, so we recommend to migrate to Fakes. Code Digger for Visual Studio 2013 and 2013 is a lightweight version of Pex that allows you to explore public .NET methods in Portable Libraries directly from the code editor.

Code Digger is the first extension from the Pex and Moles Team at Microsoft Research for Visual Studio 2012 and 2013. Stay tuned for future extensions that bring more aspects of the rich experience of the Pex Visual Studio 2010 Power Tools to the latest version of Visual Studio. If you have feedback for us, or bug reports, feel free to write an email to the Pex team at Microsoft Research. Thanks for your support, The Pex and Moles Team.