I am writing C# unit tests using NUnit and NSubstitute. I am testing a class which will attempt to retrieve objects from a config provider implementing the following interface:<
I had similar errors that started when I switched Microsoft test runner to VSTest.Console
(they did not happened when running under MSTest.exe
).
As it was advised in David's answer, the errors were caused by calls to non-substituted methods with Arg.*
parameters. Arg.Any
were passed to actual code methods, that where called without Returns
or Received
relevant methods.
To scan my test library for such issues I used search with regular expression to find rows with Arg.
but not Arg.
following by Returns
or preceded by Received
(?=^.*Arg.*$)(?=^((?!Arg.*\.Returns).)*$)^((?!\.Received\(.*Arg.).)*$
It's not bullet proof filter (e.g it doesn't exclude multi-line statements), but it helps to reduce number of calls to check.