问题
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 out there for C#2.0/.NET3.0, or whether I'm stuck banging my head against Rhino in the absence of Moq.
回答1:
I personally distinguish three kinds of mocking frameworks(in order of emergence):
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.
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.
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.
回答2:
Have you looked at this question? what-c-mocking-framework-to-use
回答3:
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.
来源:https://stackoverflow.com/questions/3561524/what-are-the-predominant-net-3-0-mocking-frameworks