5

I'm trying to debug some of my unit tests in Visual Studio 2008 and have noticed that breakpoints don't seem to be halting execution.

I kind of assumed that it was as simple as setting a breakpoint and then doing "Test | Debug | Tests in current context" ... but this never actually hits the breakpoints that I've set.

Am I doing something wrong or is this just broken?

Thanks, Brandon

2
  • is this microsoft test framework or are you using anything else liek NUnit? Commented Jul 7, 2009 at 8:36
  • I normally just run all tests, the assembly is then loaded and the breakpoints becomes enabled. Maybe your assembly for some reason fails to load (assuming MS framework here) Commented Jul 7, 2009 at 8:38

5 Answers 5

2

I had this same problem until I manually attached to the aspnet_wp.exe process first and then clicked on the Debug Tests buttons. Then my breakpoints were finally hit.

Sign up to request clarification or add additional context in comments.

1 Comment

When I tried to attach it aspnet_wp.exe didn't show up. Any idea why?
1

In my case System.Diagnostics.Debugger.Break() doesn't stop at testing method.

[TestClass] public class ContactListTest { #region "Constants" public const string COVERAGE = "CoverageService"; public const string CompanyList = "CompanyList"; public const string ContactList = "ContactList"; #endregion [TestMethod] public void GetContactListTest() { System.Diagnostics.Debugger.Break(); var ex = new ServiceFilterExpression(COVERAGE); ex.Expression = new OpBeginsWith("Type", ContactList); var result = ex.FetchData(); } } 

Comments

0

if you use nUnit you have to do following

start Nunit with the DLL you want to test. then in Visual Studio go to Tools -> Attach to Process

choose your nunit process and click "Attach" then it will halt in all your breakpoints

have fun :-)

Comments

0

The official Microsoft workaround/kludge/zomg-I-can't-believe-they-can't-be-arsed-to-provide-this-after-4-years for MSTEST in VS2010, VS2008, and VS2005 is to add System.Diagnostics.Debugger.Break() to the unit test you want to begin debugging from. This works for all projects with debug symbols referenced by the unit test project.

The .NET runtime will prompt you to dump into debug mode (or close the executing unit test program, or ignore the debug line), and (sometimes) allow you to use instance of visual studio that launched the unit test to do so. You can always debug from a new VS instance. Once you hit that System.Diagnostics.Debugger.Break() line, all other breakpoints will be active and hit (assuming they're in the execution stack).

Comments

0

Check the following:

  • Are the tests marked with [TestClass] and [TestMethod]?
  • Are you running Debug or Release mode builds? (Doesn't make a huge difference except when it does) Debug is better.
  • Are you compiling with or without optimizations? Without is better
  • Try to run All Tests in Solution in check if you hit the breakpoints
  • and lastly, maybe you have bug and that's why you are not hitting the code?

Comments