开发者

What are the predominant .NET 3.0 mocking frameworks?

开发者 https://www.devze.com 2023-01-12 18:53 出处:网络
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 before, but I absolutely

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 before, but I absolutely hate it. To be a little more descriptive, though, it's because the interface feels clunky and unintuitive--which can be dealt with--and the documentation is either horrible or non-existent--which can't.

The essence of my question is whether there are other decently-documented, intuitive, fluent-interface frameworks o开发者_Go百科ut there for C#2.0/.NET3.0, or whether I'm stuck banging my head against Rhino in the absence of Moq.


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消