NSubstitute test works by itself, but throws Unexpected Matcher Argument in a suite

前端 未结 2 1695
遥遥无期
遥遥无期 2020-12-19 05:32

I have a unit test where I use .Returns() to return some sample data:

    [TestMethod]
    public void TestRetrieveElementsInVersion()
    {
        IRetriev         


        
相关标签:
2条回答
  • 2020-12-19 06:17

    In my case, it was a Received() call on exension method (likely because it's not virtual). So I went back to my pull request and removed every instance of it and it worked.

    0 讨论(0)
  • 2020-12-19 06:30

    This is most like due to a previous test using an argument matcher against a non-virtual method, or in a Returns statement.

    Unfortunately this can be quite tricky to debug. First step is to see if the problem occurs when you run all the test in this fixture. If so, check all uses of Arg.Is|Any in that fixture, starting with the one that runs immediately before the test that fails (if your test framework uses a predictable test order, otherwise you'll need to look at test logs to see what tests proceed the failing one).

    If it does not occur with that fixture you'll need to look through the fixtures that run beforehand to see where the left over arg matcher is coming from. It is most likely somewhere near the failing test.

    0 讨论(0)
提交回复
热议问题