Reputation: 5117
My Visual Studio 2008 IDE is behaving in a very bizarre fashion while debugging a unit test: I have a breakpoint and when I hit it and then try to step with F10 the test concludes. If I Set breakpoints on every line inside the method being tested I will end up at a random one, not the next one on the following line. I have cleaned and rebuilt the solution after a clean system restart. The behavior persists. Has anyone else experienced this and come to a conclusion.
This test only used the main execution thread (no additional threads are being created)
Upvotes: 15
Views: 13171
Reputation: 31576
My unit tests were testing under x86. Changing them to x64 worked.
Menu
Test
-> Test Settings
-> Default Processor Architecture
-> x64
.
Upvotes: 0
Reputation: 77
I just encountered the same issues and went through all the suggestions above with no luck. Come to find out at some point in the past someone had changed the method signature to be "private" when it must be "static" or "public". As soon as I changed the test method's signature back to "public", the break points started working again.
Upvotes: -1
Reputation: 1542
I ran into this in Visual Studio Community 2013. The behavior appears to be by design. When running tests, execution will not stop on breakpoints. When you want execution to stop on breakpoints, selects TEST --> Debug rather than TEST --> Run.
Upvotes: 0
Reputation: 941217
There was a post VS2008 SP1 hotfix released that solves a number of debugging problems. The KB article is here, the hotfix download is here.
UPDATE: the hotfix download location was retired, I don't know of an alternative download location. Please edit this post if you find one.
Upvotes: 27
Reputation: 33
May be it is too late to reply, I got same issue in VS2012 to fix that please check if menu Test>TestSettings> "LocalTestRun.TestRunConfig" is checked, if it is checked uncheck it and it will stop skipping the code lines. May be same for Vs2008 also work.
Upvotes: 0
Reputation: 1
Go into Project->Properties and uncheck "Optimize Code"
This is the case if you see code such as DataSet ds = new DataSet(); gets hit on the debugger but code like string Test = "Test"; gets skipped.
Upvotes: 0
Reputation: 78850
This may be as simple as a case of the testing framework not loading the same assembly that you're currently working on. I've had this happen in rare cases in NUnit, which works off a copy of your assembly under test; occasionally, it stopped copying over the most recent version. Are your breakpoints decorated with a "symbols have not been loaded" indicator?
Upvotes: 0
Reputation: 1582
Are you putting your breakpoints inside code that is part of a generated class?
I have experienced this problem on the client site of a service reference. The generated classes are partial classes with the
[System.Diagnostics.DebuggerStepThroughAttribute()]
attribute applied. Even when my breakpoint was in a different file, but still part of the attributed class, the breakpoint would be skipped.
I removed that attribute from the generated Reference.cs file and the debugger worked as I expected.
Of course, this isn't a permanent solution because if the Reference.cs file gets regenerated, the attribute comes back.
Upvotes: 2
Reputation: 792
This behaviour also happens when you have multiple threads running.
Upvotes: 3
Reputation: 15866
F10 is Step Over, F5 is continue to next breakpoint, F11 is Step Into, which executes the next line of code then waits. That is what you are probably looking for.
Upvotes: -1
Reputation: 26772
Even in a Debug build, compiler optimizations could explain this behaviour. Under project properties, "Build", verify that the checkbox 'optimize code' is turned off. I have seen this turned on by default after upgrading certain projects from .Net 1.1.
Upvotes: 2
Reputation: 2488
I had similar issues on VS 2003. It turned out that I was using wrong symbols so they could not be bind to correct source.
Make sure in a following:
p.s. try placing the DebugBreak(); function in both methods (unless this code is executed inside some loop so this might be frustrating). This should cause terminating your process when execution reach any of these functions (so you can continue with debugging from that particular place).
Upvotes: 4
Reputation: 15925
This behaviour happens if you debug the release build (since lines are optimized away).
It also happened to me in the past if by accident I'm debugging an older exe somewhere else (as set by the project config), instead of the most recently build one ;^)
Upvotes: 11