none
Debugging unit tests in VS 2012 doesn't work RRS feed

  • General discussion

  • I'm having problems debugging in VS 2012 for what I would think is a pretty simple scenario - I have a class library project and a unit test project that references it. Now when I run one of the tests in Debug I can do everything as usual (put breakpoints, check state of variables etc) but only as long as the code is inside test project. Once I step into anything from the library project the debugger behaves as if the code was optimized, i.e. I can't put breakpoints on some lines, most complex types show as null even though they actually store the correct value (because I can watch its effects once back to Unit Test code) and F10 seems to be jumping to random lines instead of the next one. I have double and triple checked that both projects are in Debug and are NOT marked as Optimized. I was also able to confirm that Modules window shows both of them as Symbols loaded.

    I should add that both projects have been created in VS 2010 and then migrated to VS 2012. They both target .NET 4.0. Also I believe I am using latest version of VS Ultimate RC (11.0.50626.1) which includes July Update, all that on a x64 Windows 7 machine.

    The worst part is that I can't reproduce it on a new solution... Any suggestions what else should I check?

    Tuesday, July 10, 2012 1:39 PM

All replies

  • Hi Piotrek,

    Thank you for posting in the MSDN forum.

    Did you get any error message? Maybe you could share us a screen shot about this issue.

    As my understanding, if we want to debug a unit test, we could debug it like the following steps.

    Right click a unit test in the Test Explorer->Debug Selected Tests, and then you would debug it with step Into (F11) or Step Over(F10).

    I try to create a simple unit test, and then debug it, and it works well in my VS 2012 RC. So if possible, you could share us a simple sample, we try to debug it.

    Please also attach your Visual Studio project, you can upload it to the sky driver, and then share the download link in your post. Please also attach a screenshot image in your post.

    If you got error messages, please also show the whole error messages in your post.

    If there's any concern, please feel free to let me know.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, July 12, 2012 7:01 AM
    Moderator
  • Hi Piotrek,

    I am writing to check the status of the issue on your side. 

    What about this problem now?

    Would you mind letting us know the result of the suggestion?

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Monday, July 16, 2012 8:59 AM
    Moderator
  • Unfortunately I cannot upload my project and as I said I can't reproduce the scenario in a brand new project. I realize that it males it quite hard to help with my problem but I was hoping for general tips that could help with this issue. I've already checked for code being in debug mode and not optimized, made sure everything is rebuild and symbols are loaded. I've also played with IntelliTrace options as well but still no difference. What else could I check/try?

    As I said it does happen only on this particular project but the steps are roughly like this:

    1. Create ClassLibrary1 and ClassLibrary1.Tests projects

    2. Create a test that tests a method in ClassLibrary1

    3. Start test in debug and step into logic inside method under test defined in referenced assembly (unit test code works fine)

    4. When inside the library method debugger doesn't show correct information i.e. no values for local variables, doesn't stop on breakpoints  and F10 jumps over multiple lines instead of just one

    Most importantly the same project works just fine in VS2010. And yes I have tried resetting my VS2012 settings in case it was some configuration problem.

    Wednesday, July 18, 2012 8:55 AM
  • Hi Piotrek,

    Sorry for my reply no help.

    Just to make this issue clearly, if you didn’t debug your test, just run the test, does it work well?

    As far as I know, the VS2012 RC supports the VS2010 unit test project.

    1. As you said that it worked well in VS2010, do you mean that you just open the same project with VS2012 RC, it has this issue when you run it?

    (1)If not, check it in this way.

    (2)If you did it, since it is hard for repro this issue, to make sure that it is not related debugger settings, maybe you could check it with the following steps.

    Tool->Options->Debugging, check the settings in VS2010 and VS2012, make sure they are similiar.

      2. If the debugging settings are similar, to make sure that it is not related to VS, do you have other VS2012 RC Environment, maybe you could check it again.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 18, 2012 9:46 AM
    Moderator
  • Hi Jack,

    I can confirm that the test and library code works correctly which is why I suspect something wrong with some debugger settings. I haven't used IntelliTrace in anger but from what I was reading about it the scenario looks to me a bit like if I was debugging an IntelliTrace session which I believe captures only some debugging information.

    Re 1. Yes I have simply opened a solution created in VS2008, which was then migrated to VS2010, in VS 2012 Beta and now using it with VS 2012 RC July Update v2. I can also switch back to VS2010 and everything works as expected.

    Re 2. I can confirm Debugger settings are the same but unfortunately I don't have another environment to try it there. It does sound like a good test though so I'll try to come up with some alternative environment.

    Thank you for your help so far!

    Regards,

    Piotrek

    Wednesday, July 18, 2012 11:37 AM
  • Hi Piotrek,

    You are welcome, but sorry for that I didn’t help you resolve this issue.

    It does sound like a good test though so I'll try to come up with some alternative environment.

    If possible, you could check it and we look forward to hearing from you. Would you mind changing this thread to “General Discussion”? If you get any update for this issue, you could change it back.

    I didn’t find the debug settings which will impact it, since we often debug it with the default settings, as you said that if it has the same result when you debug it with resetting settings, I’m afraid that it is not the VS debugging settings issue.

    My suggestion is that if you could debug it with another VS2012RC, so we could make sure that whether it is related to your VS. Maybe you could try to run your VS in /SafeMode or repair your VS and check it.

    Sincerely,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, July 19, 2012 3:21 AM
    Moderator
  • OK I've tested it on another machine and still the same problem there. So if it is not enviroment and cannot be reproduced in a brand new project but without any changes works fine in VS2010 then I would think it must be a combination of project specific settings with VS2012.

    The big question is how can I debugg it any further? And it is getting avery important question for me because we can't drop the project so this issue might stop entire company moving to VS2012...

    Piotrek

    Monday, July 23, 2012 11:52 AM
  • Bet you are using VSS for your version control.

    Open the containing folder for your application, and run properties on it. Change the readonly property to read/write for all folders and files. Then try again.


    Owen Brewer

    Tuesday, July 24, 2012 2:57 AM
  • Has there been any resolution of this problem? I am experiencing the same behavior using TFS not VSS for source control. Just like Piotrek, I can step through and into unit test code fine, but as soon as I travel outside the unit test assembly it starts skipping lines of code, won't trace into methods, etc. Also, like Piotrek, I can debug everything fine in 2010, with no issues.


    Eric

    Tuesday, August 7, 2012 3:36 PM
  • I am still strugling with this with not much hope for a solution.

    And just to clarify I am using TFS and more importantly I am using it in exactly the same way in VS2012 as in VS2010

    Tuesday, August 7, 2012 5:24 PM
  • Ok, I've stumbled upon something here.

    Under Test | Test Settings I unchecked the test settings file that was selected and everything started working as expected. Breakpoints were hit and I was able to trace into methods as expected.

    Knowing that code coverage has been problematic for me at best I re-selected the test settings file, but turned off code coverage, and once again everything worked as expected.

    I then turned code coverage back on and everything continues to work as expected, but adding a dll to the code coverage configuration brings the problem back.

    So long story short, turning off code coverage analysis in my existing test settings file seems to have fixed the problem for me.


    Tuesday, August 7, 2012 6:19 PM
  • Thanks Lunarwave! With your great tip I was able to confirm that turning code coverage off solves the problem and I can debug my tests as before.

    Moreover I was able to reproduce the scenario in a simple project but only when I create the original project in VS2010, enable code coverage and only then migrate to VS2012. I would think that this is not a desired behaviour so I'll be posting my project to MS Connect as a bug and will use tests without code coverage for now.

    Thanks again!

    Wednesday, August 8, 2012 12:04 PM
  • For anyone following this there is a response from Microsoft Connect and it basically confirms what we've already found with a promise of fixing it in a future update...

    https://connect.microsoft.com/VisualStudio/feedback/details/757483/debugging-assembly-with-code-coverage-enabled-doesnt-work-as-expected

    Friday, August 10, 2012 8:50 AM
  • I faced the same problem by upgrading from visual 2010 to visual 2012,  unit tests running was well, but when you debugging,  debugger can't hit the right line, the watch variable is not correct.

    I fixed it by remove the old test settings file under solution folder, hope this will help anyone who face the same problem.

    Monday, September 17, 2012 9:06 AM
  • I faced the same problem by upgrading from visual 2010 to visual 2012,  unit tests running was well, but when you debugging,  debugger can't hit the right line, the watch variable is not correct.

    I fixed it by remove the old test settings file under solution folder, hope this will help anyone who face the same problem.

    Removing the settings file worked for me as well.   (I.e., remove it from the solution, delete it from the hard drive, and restart Visual Studio.)

    I was having the exact same issue when trying to debug tests  in VS.NET 2012 from a project that was created in 2010... the debugger was skipping lines all over the place, wouldn't let me set breakpoints, and wasn't even setting values correctly (everything was 'null').   Seems to me like VS.NET 2012 isn't quite as "backwards compatible" as it's being advertised to be.


    Sincerely,
    Todd M. Taylor

    Tuesday, September 25, 2012 3:09 PM
  • We had the same issue. After reading this thread I had a closer look at the local.testsettings file. It turned out there was a CodeCoverageItem referencing the dll I was trying to debug.

    I removed the AgentRule section from the local.testsettings file and I was able to debug again.




    • Edited by ncu Monday, October 8, 2012 2:43 PM
    Monday, October 8, 2012 2:34 PM
  • We had the same issue. After reading this thread I had a closer look at the local.testsettings file. It turned out there was a CodeCoverageItem referencing the dll I was trying to debug.

    I removed the AgentRule section from the local.testsettings file and I was able to debug again.




    Johnson Yang's solution worked for us, too. We looked into it a bit more also found that it seemed to be related to code coverage that was enabled in VS2010.

    I haven't tested this, but I suspect you could disable the "old-way" code coverage from within VS2012 and then re-enable it, if backward compatibility with VS2010 is needed, to resolve the issue.

    Thanks for the help, Johnson/Todd/ncu!

    Wednesday, October 31, 2012 9:57 AM
  • Lunarwave, you just put an end to hours of my frustration! Disabling VS2010-style code coverage fixed this problem. Thank you!

    Daniel Stolt, Perceptible, http://www.perceptible.net

    Saturday, November 10, 2012 11:29 PM
  • This did the trick for me and my co-workers. Thanks Lunarwave.

    Siggi


    Monday, January 7, 2013 12:57 PM
  • Hi Jack,

    Am facing similar problem, while debugging the Unit test the mapping of control in the source code is not flowing correctly. I have checked the modules and found that the module loaded for my Visual Studio 2012 is QTAgent.exe. But I have seen a different module getting loaded in peers machines that is vstest.executionengine.x86.exe(and here debugging works fine). The difference in the machine setup is, I have visual studio 2005, 2008, 2010 and 2012 in my machine. Before I got the visual studio 2012 ultimate, i had installed and uninstalled the 2012 express. 

    Is there any way to rectify the debugging in my machine? Many thanks in advance.

    Regards,

    Sujith

    Friday, January 25, 2013 12:44 AM
  • I have tried installing the update 1 for visual studio 2012, and after that the debugging found working. Still the VS uses QTAgent32.exe for the unit testing.

    -Sujith

    Monday, January 28, 2013 5:23 PM
  • Hello All,

    I have found the same issue with the VS 2012 alone in a fresh windows. While debugging the control doesn't map to the correct line in the code. This is seen even after installing the VS 2012 update 1. We could get a workaround for this issue by disabling the code coverage, but still doesn't know why its so.

    -Sujith

    Tuesday, January 29, 2013 8:46 PM
  • This may have to do with targeting "Remote Execution".

    Sean Sullivan

    Monday, April 15, 2013 5:10 PM
  • Also have experienced this with Update 2 installed.
    Thursday, August 8, 2013 3:15 AM
  • Thanks a lot. I struggled too much.


    Thanks & Regards, Preetham


    Thursday, August 8, 2013 9:53 AM
  • It happens to me as well.

    What i noticed was the DLL that i referenced in my UnitTest project is also deployed to the GAC (which is of older version).

    The Unit Test takes the copy in the GAC and not the one you just updated in your VS.

    Hence, You need to update your latest DLL into the GAC, probably by running a post build event gacutil -i yourssembly whenever you compile your dll.

    With that, then only your UnitTest can step through the codes in the referenced DLL.


    Cheng

    Wednesday, November 12, 2014 3:52 AM