开发者

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();
}


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜