locked
Not able to step through (Debug) code from VSTS test method after migration project from VSTS 2010 to VSTS2012. Not getting Code Coverage RRS feed

  • Question


  • Dear Team,

    I have migrated project (WCF) from VSTS 2010 to VSTS 2012. After migration, I’m not able to debug the code through test method. Test methods give perfect result (Pass/Fail) but not able to debug and not able to get Code Coverage.

    Snippet of my test method –

    string url = “http://localhost:34567/” + "getpagebyid?id=" + testPageID;

    HttpWebRequest request2 = WebRequest.Create(url) as HttpWebRequest;

                request2.Headers.Add("controldata", "{'UserCredentialData':{'UserId':'" + userName + "', 'AccountId':'9PRO001900', 'Namespace':'16'}}");

    request2.Method = "GET";

                request2.ContentType = "application/json;charset=utf-8";

                request2.Timeout = 600000;

                var sb_getbyID = new StringBuilder();

                // string sb = string.Empty;

                using (var response = request2.GetResponse())

                {

                    using (var stream = response.GetResponseStream())

                    {

                        var buffer = new byte[8192];

                        for (; ; )

                        {

                            var count = stream.Read(buffer, 0, buffer.Length);

                            if (count <= 0)

                                break;

                            sb_getbyID.Append(Encoding.Default.GetString(buffer, 0, count));

                        }

                    }

                }

    In VSTS 2010, when I debug above method, I can debug actual WCF service – getpagebyid method and I was getting test/code  coverage too.

    Note: For code coverage, I have configure “Date and Diagnostics à Code Coverage” for  Local.testsettings.

    Please help me to get code coverage and debug service's method.

    Regards,

    Mitesh Sheth

    Monday, June 23, 2014 12:53 PM

All replies

  • Hi,

    Please provide us more information:

    When migrating WCF project to VS2012, whether you got some errors?

    If you run/debug the WCF project itself, whether you can do it successfully?

    You said that you can’t debug the WCF project through test method, what errors did VS report?

    You know this is a forum for VS testing issues, about debugging WCF service, you also can consult on WCF forum: http://social.msdn.microsoft.com/Forums/vstudio/en-us/home?forum=wcf. Or VS debug forum: http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vsdebugI think that  experts there can provide you some help.

    Whether the WCF service hosted locally? We currently only support solutions that are hosted from within Visual Studio. So if you want to do code coverage for a windows service or any component not being run as a part of VS, you can either use the VS2010 toolset (vsperf/vsinstr) which is available in VS2012 as well.

    Where did you create this test method? VS2010 or VS2012?
    I assume that you created a unit test from VS2012 after you migrated VS2010 WCF project to VS2012. The code coverage collection feature in VS2012 test setting file is applied for VS2010 project. In VS2012, we collect code coverage through right clicking the test method and selecting ‘Analyze Code Coverage for selected test’.

    Thanks,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Amanda Zhu Tuesday, June 24, 2014 11:47 AM edit
    Tuesday, June 24, 2014 11:34 AM
  • Hi,

    When I debug test method,  I'm not getting error but i am not able to step in the method. Test method.

    I haven't got any error during migration from VSTS 2010 to VSTS 2012.

    Test project is written in VSTS 2010 along with WCF code. Test method working as expected in VSTS 2010 but not in VSTS 2012.

    Regards,

    Mitesh Sheth

     

    Tuesday, June 24, 2014 5:20 PM
  • Hi Mitesh,

    Thank you for your information.

    Based on the different server where the wcf service run, VS provides different ways to debug it within unit test. Note that ASP.NET production code cannot be stepped into unless debugging is enabled and the debugger is attached to the ASP.NET Development Server or the IIS process.

    If your wcf service is running on ASP.NET Deployment Server, then you need use statement System.Diagnostics.Debugger.Break() to debug.

    For more information, please see:

    How to: Debug while Running a Test in an ASP.NET Solution

    And Edward Brey also provided detailed steps to debug service when the service is hosted in IIS in this thread with similar issue:
    http://stackoverflow.com/questions/15440913/visual-studio-2012-unit-test-client-and-service-debug

    1.Start the wcf service  without debugging (if it's not already running).

    2.Put a breakpoint in your unit test.

    3.Start your unit test.

    4.When the breakpoint is hit, use Debug > Attach to Process to attach to iisexpress.exe.

    As for the code coverage, whether you got any errors when you open the Code Coverage result window? Please share us if yes. As I said before, in VS2012, we can collect code coverage through right clicking the test method and selecting ‘Analyze Code Coverage for selected test’. Please do it like this to check the result.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, June 30, 2014 2:43 AM
  • Hi,

    I have hosted service locally so which process i should attached for debugging?

    Regards,

    Mitesh

    Wednesday, July 2, 2014 8:11 PM
  • Hi,

    Thank you for your response.

    What did you mean ‘hosted locally’? If you host wcf in local iis, before you debug the test method, please attach iisexpress.exe as I suggested in my previous reply.

    Please tell me that whether you can debug the WCF separately successfully from VS2012 IDE without from test method? In order to make sure you can debug wcf from test method, please make sure you can debug wcf itself from VS successfully first.

    In addition, based on your test code, whether you work with WCF Rest service or WCF soap service? Please correct.

    Thanks,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 3, 2014 10:17 AM
  • it is WCF rest services. I have tested the way you have suggested but same result.

    I can debug the service through fiddler not from the test methods. 

    Test methods originally written in VSTS2010 and i have recently migrated in VSTS 2012. 

    Regards,

    Mitesh Sheth

    Wednesday, July 9, 2014 9:21 PM