resharper and ExpectedException attribute message / match type

52 views
Skip to first unread message

Berryl Hesh

unread,
Jan 2, 2009, 1:57:26 PM1/2/09
to NUnit-Discuss
I have more than a few tests which use this attribute, like the one
below. I used to always use TestRunner.Net, which handles the test as
expected just fine as a passing test. I've been using Resharper 4.1
for testing lately, which reports the same test as an error, and was
wondering if this is a known issue to this group.

As an aside, I know this is really a Resharper issue. I find their
site less than helpful though, and as much as I love their product it
seems the only thing they seem to communicate really really well is
when to spend money on an upgrade. I don't even know how to get
regular maintenance releases, or if they even offer them!

Sorry for the mini-rant. Thx - BH

---x-- test that should and does work when not using resharper --
xx------------
[Test][ExpectedException("System.ArgumentNullException",
ExpectedMessage = "'System.Globalization.RegionInfo' may
not be null.", MatchType = MessageMatch.Contains)]
public void CreateWithNullRegionThrowsException()
{
const RegionInfo ri = null;
Currency.Create(ri);
}

xx-- error from resharper --xx--
CurrencyTest.CreateWithNullRegionThrowsException : FailedExpected
exception message: 'System.Globalization.RegionInfo' may not be null.
got: 'System.Globalization.RegionInfo' may not
be null.
Parameter name: System.Globalization.RegionInfo
System.ArgumentNullException: 'System.Globalization.RegionInfo' may
not be null.
Parameter name: System.Globalization.RegionInfo
at Smack.Core.Exceptions.efAssert.NonNull(Object arg, String
nameForParameter, String additionalIdentifyingName) in efAssert.cs:
line 49
at Smack.Core.Exceptions.efAssert.NonNull(Object arg, String
nameForParameter) in efAssert.cs: line 37
at Smack.Core.Exceptions.efAssert.NonNull<T>(Object arg) in
efAssert.cs: line 19
at Smack.Core.Domain.Financial.Currency.Create(RegionInfo ri) in
Currency.cs: line 73
at
Smack.Core.Tests.Domain.Financial.CurrencyTest.CreateWithNullRegionThrowsException
() in CurrencyTest.cs: line 35

Kelly Anderson

unread,
Jan 2, 2009, 3:05:43 PM1/2/09
to nunit-...@googlegroups.com
Berryl,

It is my understanding that the test runner bundled with Resharper
is one that they have written themselves that mimics NUnit (about
version 2.4 last I checked) and there have been a lot of changes since
then. If the Resharper folks would use the NUnit source code instead
of having rewritten it themselves, they would be able to keep up more
effectively. I don't fully understand their decision to do things that
way, and it does cause some trouble. I believe TestDriven.NET does a
better job of keeping up with current NUnit versions... comments
anyone?

I'm a big fan of Resharper, and have found that they generally respond
to support emails to registered users very rapidly. If you haven't
tried an email to their support desk, I would try that.

-Kelly

Charlie Poole

unread,
Jan 2, 2009, 3:12:18 PM1/2/09
to nunit-...@googlegroups.com
Hi Berryl,

As has already been pointed out, Resharper doesn't use NUnit
to run NUnit tests. That means they have to revise their code
in order to match changes in NUnit. In this case, my guess
(like yours) is that they don't handle the match type.

Best workaround for this particular example would be to
switch to NUnit 2.5 as soon as it's stable enough for
your purposes and then use either Assert.Throws or
Assert.That with a ThrowsConstraint. That puts all
the logic for detecting the correct message into
the Assert, which is part of your own code and which
Resharper executes.

Charlie

Berryl Hesh

unread,
Jan 2, 2009, 7:30:16 PM1/2/09
to NUnit-Discuss
@Kelly - thanks for the tip about trying jet brains help support.

@Charlie - I hadn't realized 2.5 was so robust. Good show!!
Reply all
Reply to author
Forward
0 new messages