4

I'm new to C#/.NET but I've been doing TDD for quite some time now. I want to know what is the best framework that can be used for mocking objects while writing tests in C#?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
gprasant
  • 15,589
  • 9
  • 43
  • 57
  • http://stackoverflow.com/questions/37359/what-c-mocking-framework-to-use http://stackoverflow.com/questions/1718463/what-are-the-real-world-pros-and-cons-of-each-of-the-major-mocking-frameworks http://stackoverflow.com/questions/642620/what-should-i-consider-when-choosing-a-mocking-framework-for-net – Jørn Schou-Rode Mar 16 '10 at 09:10
  • Refer [Poll - Which Isolation(mocking) framework do you use in .NET?](http://polldaddy.com/poll/3746444/) and [Why do we need yet another NET mocking framework](http://blogs.clariusconsulting.net/kzu/why-do-we-need-yet-another-net-mocking-framework/) – LCJ Feb 03 '14 at 10:17

3 Answers3

5

Popular options

Moq and Rhino are both regular mock/stub framework. TypeMock Isolator is a bit special, as it modifies the IL to allow mocking of types you have no control over. Some like this a lot. Others feel it is too intrusive.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
  • My recommendation is for Rhino Mocks - although the lambda syntax of Moq is nice, Rhino Mocks can do some things that Moq is unable to do as yet, for example, support for ref and out parameters. Haven't tried TypeMock but can imagine it being very useful when there is absolutely no way that one is able to change the code under test. – Russ Cam Mar 16 '10 at 08:57
  • 3
    Also, Moq and Rhino are free, which is not the case of Typemock... – Mathias Mar 20 '10 at 03:55
3

Moles allows to replace any .NET method with a delegate. Any method including static methods or methods in sealed types.

Peli
  • 2,465
  • 16
  • 17
0

You can try Rhino Mocks or NMocks

hallie
  • 2,760
  • 19
  • 27