What are the predominant .NET 3.0 mocking frameworks?

后端 未结 3 2067
独厮守ぢ
独厮守ぢ 2021-01-23 19:55

To preface this, I love Moq. I wish I could use it in .NET 3.0. Sadly, however, I cannot, but I would still like to use mocks for unit testing purposes. Also, I\'ve used Rhino b

相关标签:
3条回答
  • 2021-01-23 20:16

    I personally distinguish three kinds of mocking frameworks(in order of emergence):

    1. Arrange-Act-Assert (AAA) using string method names ala NMock2/NUnit Mocks. Pretty easy to get going but is not strongly typed. If method/property is renamed then the test will fail at runtime.

    2. Record-and-replay ala Rhino Mocks. I totally agree with you, the syntax sucks and I hate using it. It is fully strongly typed so when you refactor a method, the test stays up to date.

    3. AAA using lambdas and expressions. These include MOQ, Latest AAA releases of Rhino Mocks and Typemock Isolator. By far the best syntax, but requires .NET 3.5.

    If .NET 3.5 is unavailable, I am afraid that you have to pick the least evil - horrible Rhino Mocks syntax or late binding to method/property names.

    PS. Microsoft has its own isolation framework called Moles. I haven't checked it out myself, but it's supposed to be fairly powerful (i.e. mocking static methods, non-public methods etc). Check it out here.

    0 讨论(0)
  • 2021-01-23 20:16

    NUnit has mocking available, so if you're already testing with that, then you should be good to go already. Just include NUnit.Mocks.

    It doesn't fulfill your fluent-interface desire though.

    0 讨论(0)
  • 2021-01-23 20:32

    Have you looked at this question? what-c-mocking-framework-to-use

    0 讨论(0)
提交回复
热议问题