Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

NCrunch 3.13.0.7 gives intermittent UnexpectedArgumentMatcherException errors
rdavis
#1 Posted : Monday, March 12, 2018 10:53:42 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/26/2015(UTC)
Posts: 3
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
After upgrading to NCrunch 3.13.0.7, I'm getting regular occurrences of an UnexpectedArgumentMatcherException. They're occurring at most once per test run, and the exception message is like this:

Quote:
SetUp : NSubstitute.Exceptions.UnexpectedArgumentMatcherException : Argument matchers (Arg.Is, Arg.Any) should only be used in place of member arguments. Do not use in a Returns() statement or anywhere else outside of a member call.
Correct use:
sub.MyMethod(Arg.Any<string>()).Returns("hi")
Incorrect use:
sub.MyMethod("hi").Returns(Arg.Any<string>())


Re-running the test always clears the exception.

However, none of my tests use Arg.Any inside a Returns method call. An example line that produces this exception is

Code:
_mockDateTimeProvider.UtcNow.Returns(_defaultDateTime);

where _mockDateTimeProvider is an object created by AutoFixture, and _defaultDateTime is a static DateTime object.

Is there perhaps something else causing these exceptions, or is this an issue in the 3.13.0.7 version of NCrunch?

Thanks!
Remco
#2 Posted : Tuesday, March 13, 2018 4:53:12 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,230

Thanks: 691 times
Was thanked: 840 time(s) in 800 post(s)
Hi, thanks for sharing this issue.

Does the exception appear with any consistent stack trace? Are you able to get a debugger on it?

(NCrunch itself has no integration with NSubstitute).
rdavis
#3 Posted : Tuesday, March 13, 2018 8:46:24 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 1/26/2015(UTC)
Posts: 3
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
Thanks for the reply. I found that this issue was raised on StackOverflow a while ago - https://stackoverflow.com/questions/38283104.

In our case, a couple of tests were using AutoFixture's fixture.Create<T1>() method to build an object, and then passing Arg.Any<T2>() as a parameter in a method call on this object. This causes NSubstitute's static queue to get out-of-sync, as explained well here: https://weareadaptive.co.../09/30/why-nsubstitute/

Replacing these parameters with fixture.Create<T2>() fixed the issue.

So this was not a problem with NCrunch, but some change between 3.12.0.15 and 3.13.0.7 made this problem more likely to be visible. But that's a good thing!
1 user thanked rdavis for this useful post.
Remco on 3/13/2018(UTC)
Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.024 seconds.