Moq, NSubstitute, Testing, Test
Moq vs NSubstitute favoring NSubstitute
There are two popular mocking frameworks called Moq and NSubstitute,
among many. Both work great and the
negative consequences of choosing one over the other are small. But
there are differences and the purpose of this post is to contribute to
that general discussion.
The interwebz have already done some great comparisons.
The two main points of this post is that the extra setup syntax of Moq
is subjectively negative and that NSubstitute supports named parameters
and Moq doesn't.
Named parameters are a feature of C# and documented here
. In general named parameters can make your code more readable when the
name of the input parameter contributes to the readability of the
calling code. Stackoverflow
has a couple examples.
NSubstitite supports them but Moq does not.
As this and other examples show, you will spend time writing lambda
syntax and fetching the usable object (mock.Object) when using Moq as opposed to NSubstitute.
It's not a show
stopper to choose either, but if you like named params and don't like
the extra setup syntax then NSubstitute might be your winner.