Anders Nygaard
Anders Nygaard

Reputation: 5552

Why does ReSharper's test runner ignore ExpectedException?

when I run the following example with the debugger in Visual Studio 2010 (using TestDriven.NET), I get a pass, but when I run it with the ReSharper test runner, I get a fail. The test is written with Microsoft's test framework.

How can I set this up right? I basically just want to call a method with illegal input and I expect it to throw an exception.

[ExpectedException(typeof(System.Exception))]
[TestMethod]
public void TestSomething()
{
    throw new System.Exception();
}

Upvotes: 8

Views: 1109

Answers (2)

geeTee
geeTee

Reputation: 1147

Change it to use a less generic Exception (i.e, not System.Exception)

[ExpectedException(typeof(UnauthorizedAccessException))]
[TestMethod]
public void TestSomething()
{
    throw new UnauthorizedAccessException();
}

ReSharper seems to not handle ExpectedException with System.Exception that well, which in a way is good. Be specific about your exceptions.

Upvotes: 4

Anders Nygaard
Anders Nygaard

Reputation: 5552

Also, be sure to include the right version of Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

Upvotes: 3

Related Questions