When you write unit tests for your ASP.Net applications you may at some point need to debug these tests. Although the Visual Studio’s Test menu has an option to debug your tests, I found this doesn’t work when running ASP.Net tests.

A simple way around this is to use the Debugger class located in the System.Diagnostics namespace. The code snippet below shows how you would place a call to the Debugger.Break() method before the line of code you wish to start debugging at.
[TestMethod]
[HostType("ASP.NET")]
[UrlToTest("http://localhost/AspNetTDD1/Default.aspx")]
[AspNetDevelopmentServerHost(@"C:\code\AspNetTDD1\AspNetTDD1", "/AspNetTDD1")]
public void TestMethod1()
{
System.Diagnostics.Debugger.Break();
Page page = _testContextInstance.RequestedPage;
Button button = page.FindControl("Button1") as Button;
Label label = page.FindControl("Label1") as Label;
PrivateObject po = new PrivateObject(page);
po.Invoke("Button1_Click", button, EventArgs.Empty);
Assert.AreEqual("Did you hear that? They shut down the main reactor.
We'll be destroyed for sure", label.Text);
}
Now if you run your tests you will see the following dialog box.

You should click the Debug button which will display the Visual Studio Just-In-Time-Debugger dialog, here you should click the Yes button. This will open an new instance of Visual Studio with the code relating to the test loaded. You can now debug the test code using the standard options of Step Into (F11), Step Over (F10) etc.