TestMethod Visual Studio 2010上的ExpectedException [英] ExpectedException on TestMethod Visual Studio 2010

查看:288
本文介绍了TestMethod Visual Studio 2010上的ExpectedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我将所有的基础项目从VS2008升级到VS2010。一切顺利,除了我的单元测试。

Today I upgraded my solution with all the underlying projects from VS2008 to VS2010. Everything went well except for my unit tests.

首先只有web项目有目标框架.NET 4.所有其他项目仍然有.NET 3.5。我把它们全部改为.NET 4。

First of all only the web projects had as target framework .NET 4. All the other projects still had .NET 3.5. I changed them all to .NET 4.

现在当我调试我的单元测试时,它打破了每一个异常。在2008年,它只是不会通过,告诉我,发生了一个异常。即使我定义了ExpectedException属性,它也会停止对每个异常的调试。

Now when I debug my unit tests it breaks on every exception. In 2008 it just wouldn't pass and tell me that an exception occurred. Even when I have the ExpectedException attribute defined it stops debugging on every exception.

我的一个测试示例:

[TestMethod]
[ExpectedException(typeof(EntityDoesNotExistException))]
public void ConstructorTest()
{
    AddressType type = new AddressType(int.MaxValue);
}

EntityDoesNotExistException是一个自定义异常并继承异常。

The EntityDoesNotExistException is a custom exception and inherits Exception.

编辑
我在2008年和2010年查看了例外设置(ctrl + alt + e)。在这两个版本中的设置都是一样的。但是在2008年的调试不会打破,当我有ExpectedException属性。

Edit I looked at the Exceptions settings (ctrl+alt+e) in 2008 and 2010. In both versions the settings are the same. However in 2008 the debug doesn't break when I have the ExpectedException attribute. In 2010 it does break.

推荐答案

根据Microsoft的说法,这不是一个错误,它是设计:

According to Microsoft, this is not a bug, it's "by design":

http://connect.microsoft.com/VisualStudio/feedback/details/511897/expectedexception-still-causes-debugging-to-break-with-exception-was-unhandled-按用户代码

这篇关于TestMethod Visual Studio 2010上的ExpectedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆