NSubstitute - TestFixture 1 causes AmbiguousArgumentsException in TestFixture 2

前端 未结 3 744
[愿得一人]
[愿得一人] 2021-02-08 10:14

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:<

3条回答
  •  天涯浪人
    2021-02-08 10:50

    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.

提交回复
热议问题