ExpectedException on TestMethod Visual Studio 2010

前端 未结 8 842
心在旅途
心在旅途 2020-12-31 02:34

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 project

相关标签:
8条回答
  • 2020-12-31 03:05

    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.

    0 讨论(0)
  • 2020-12-31 03:07

    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!

    0 讨论(0)
  • 2020-12-31 03:10

    I ended up changing my tests to this form to avoid the breaking. Not ideal:

      [TestMethod]
      public void Guid()
      {
         try
         {
            Guid g = new Guid("myguid'123'");
         } 
         catch( FormatException fe)
         {
            return;  // expected exception - pass
         }
    
         Assert.Fail(); // exception not thrown - fail
      }
    
    0 讨论(0)
  • 2020-12-31 03:15

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

    0 讨论(0)
  • 2020-12-31 03:19

    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-by-user-code

    0 讨论(0)
  • 2020-12-31 03:23

    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.

    0 讨论(0)
提交回复
热议问题