views:

375

answers:

6

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.

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.

A: 

Tools - Options - Debugging

Not sure which option though :(

mafutrct
+1  A: 

Press Ctrl+Alt+E and check the break on exception setting for CLR exceptions. If this is set to true then the behavior you described will occur.

Gerrie Schenck
That means this has been changed in 2010? Are those settings project or solution depended?
Joop
I have two options: break on exception is thrown and break on exception is user-unhandled. Only the last option is checked for CLR exceptions.
Joop
Part of the solution indeed starts here. See my own answer for details.
Dabblernl
A: 

I've had the same issue, but finally managed to get it working. Not really sure how but here's a list of things I did between it not working to when it started working again.

  • Converted the project being tested to .NET 4
  • Turned off CodeCoverage
  • Turned CodeCoverage back on again
  • Did a RebuildAll on the test project

Not sure which bit fixed it though. Anyway, hope this helps!

Jon Mitchell
I have VS2010 Professional. Code coverage only is available in Premium and Ultimate. But thanks for the suggestion!
Joop
Something else that I think I did was go on Test->Edit Test Settings and then did a Save As, over writing the previous file. In theory this shouldn't have an effect but I did read that someone deleted his test settings file and that sorted his issue. HTH
Jon Mitchell
Unfortunately this also isn't working. Really strange behavior.
Joop
+1  A: 

Make sure your reference to Microsoft.VisualStudio.QualityTools.UnitTestingFramework is Version 10.0.0.0.

If it is version 9.0.0.0 this problem will occur in Visual Studio 2010.

Hope this helps. If people still have this problem.

Einarsson
In my test project I already use version 10.0.0.0.
Joop
-1: vs 2008 supports ExpectedException
John Saunders
@John: It is not because 2008 does not support expected exceptions. It's because the attribute classes are not the same. If you reference the test framework of 2008, the compiler puts the attributes of 2008 on your test class. The test runner only checks for the attribute of 2010 (different assembly => different class), so it doesn't recognize the attribute at all. We had the same problem.
Stefan Steinegger
Stefan explained well what I was trying to say. :)
Einarsson
+1  A: 

Gerrie pointed me in the right direction:

  • Press Ctrl-Alt-E
  • Open the Common Language Runtime Excepions Node
  • Click Add
  • Type Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException
  • Make sure that both checkboxes are unchecked.

This will get rid of the break on failed Asserts, but the test will still break when you have set an ExpectedException.

I was the one that set the 100 bonus for this, so some upvotes would be appreciated ;-)

Dabblernl
A: 

A Microsoft support guy told me to use Ctrl-F5 (start without debugging) when running my unit tests, and that seems to work.

Another thing to try is to go to Tools|Options|Debugging and un-check the "Enable Just My Code" option.

rlandster