3 ms·
I use Moq and enjoy it. I previously used NMock a little bit, and it was a big pain. The reasons Moq is cool, when compared with other such frameworks, includ
by mullr 16y ago
I use Moq and enjoy it. I previously used NMock a little bit, and it was a big pain. The reasons Moq is cool, when compared with other such frameworks, include:
1) The mock setup routines use a clever and increasingly common hack involving expression trees (lambdas) to remain strongly typed, which fits nicely with the rest of the language.
mockObject.SetupGet(ob => ob.prop).Returns(42);
2) You can easily mock out a chain of property accesses with just one call, rather than having to set up a bunch of intermediate objects.
mockObject.SetupGet(ob => ob.propA.propB.propC).Returns(42);
3) It doesn't matter what order the mocked methods are called in; in many ways it's more like a dynamic stub generator than a traditional mock object framework. Some people probably think this is a bad idea; those people can use another library. I like this mode, I think it makes it a lot easier to start using. And for testing libraries, that's possibly the most important part.