I have a class that looks like this:
public class MyService
{
private MyService(){}
public static string GetStuff()
{
var stuffDid = new MyService();
return stuffDid.DoStuff();
}
private string DoStuff()
{
//do stuff
}
//other private helpers
}
Obviously I left a lot out, but thats the general shell.
Now, I have a unit test:
[Test]
public void MyTest()
{
var results = MyService.GetStuff();
}
I set breakpoints on my unit test, and I can see that results
has data. However, I set breakpoints literally all over MyService
and nothing gets hit unless I put them on a curly brace. Which I can't understand since results
has data, my return
statements in MyService
should be getting hit, right?
Am I missing something? Did I completely forgot the most basic rules of something? How come nothing in MyService
gets hit? And if I manually step into it with F11
, it just hops around and doesnt even go thru every line like I would expect. Also when I step thru manually I tend to hit certain code after I should have hit it originally. And any switch
statements seem to default to whatever the first option is, even tho the value being switched should CLEARLY enter a different case
.
I've even tried making MyService
constructor public
and taking away all static
methods, and it still doesnt work.
Edit:
My Tests and 'Core' code are in the same solution, but different projects(Test
and Core
, respectively). Other tests don't have an issue hitting break points in Core
, only this on particular test(the only test that is testing MyService
.
Edit 2:
I've deleted my PDB files and cleaned solution. Still nothing.
I know from experience that Visual Studio does not have a clear method of debugging services, especially Windows services. Try adding some code to GetStuff to print to a text file, this way you at least know the code is getting hit. When creating services I often fall back on this method for testing.
I ran into a similar issue. It turned out that for me it was a bad migration from VS2010 to VS2012 with the
*.testrunconfig
file. I deleted the old one and set up a new one to resolve the issue.Maybe your
Test
project is referencing an olderCore
binary, rather than theCore
(source code) project?Try re-adding the reference in your Test project:
Go to your
Test
project and remove the reference to theCore
project.Now select the References folder and right click it and select the menu option to add a new reference. When in the Reference Manager dialog, make sure you are selecting
Solution
and thenProjects
on the left. Then in the middle of the Reference Manager dialog, select (check) theCore
project.Try debugging again and see if that helps.
In Unit Tests, I was not hitting breakpoints, and realized I was Running the test and not Debugging the test. At the top of the Test Explorer are the options "Run All", "Run Failed", "Run Passed", etc. When you Run a test, breakpoints are not hit. To Debug a test, in the Test Explorer right click on the test or group of tests and select Debug Selected Tests.
This one's pretty obscure :
Make sure you don't have two virtual directories with different App Pools pointing to the same physical location on your harddrive. During development this is something that can sometimes happen for testing, or by mistake.
I'm not 100% clear on the technicalities but I had two AppPools and two virtual directories and no breakpoint was ever hit because I presume the physical path was somehow mapped in IIS/Visual Studio to the other apppool and not the one that was actually executing.
I have the same issue. Maybe my solution will help you to solve your problem. Just in "Attach to Process" for option "Attach to" select value "Avtomatic: Native code". Best regards.