none
Unable to debug method with Code Contract statements, when executing unit tests

    Question

  • Environment: Windows Server 2012 R2, Visual Studio 2015 Update 1

    Issue:

    When I debug a Unit Test, which is testing a method that contains Contracts, as soon as I let the execution flow on the Contract statement, the flow stalls / stops. The test doesn't proceed to the next line. It feels like the execution is stuck within the Contract execution and does not get out, even though the result on Contract is a true.

    Sample Method under Test:

    public Stuff GetMyStuff(string myId)
    {
         Contract.Requires<ServiceArgumentException>(myId != null && myId.Trim().Length > 0, "Invalid parameter: myId");

         var status = "I reached here";

         ......

         return Stuff;

    }

    Sample Unit Test:

    public void GetMyStuffValidTest()

    {

         Stuff me = GetMyStuff("0123456789");

         // Assert me

    }

    Note: I have breakpoints on the Contract statement and on the var status. However once I let the execution proceed passed Contract, it never comes back to the var status statement.

    Will appreciate any pointers. I've searched the web and multiple documentations, but have had no luck identifying the cause.

    Thanks.



    • Edited by DesiHero-007 Tuesday, December 29, 2015 7:08 AM further clarity
    Tuesday, December 29, 2015 6:55 AM

Answers