ExpectedException on TestMethod Visual Studio 2010

Posted by Joop on Stack Overflow See other posts from Stack Overflow or by Joop
Published on 2010-04-13T11:07:17Z Indexed on 2010/04/13 11:13 UTC
Read the original article Hit count: 344

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

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.

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.

And example of one of my tests:

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

The EntityDoesNotExistException is a custom exception and inherits Exception.

© Stack Overflow or respective owner

Related posts about c#4.0

Related posts about visual-studio-2010