Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
}
like image 550
Anders Nygaard Avatar asked Jul 14 '11 12:07

Anders Nygaard


2 Answers

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.

like image 117
Geir-Tore Lindsve Avatar answered Nov 01 '22 09:11

Geir-Tore Lindsve


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

like image 24
Anders Nygaard Avatar answered Nov 01 '22 08:11

Anders Nygaard