我正在尝试在 Visual Studio 2008 中调试我的一些单元测试,并注意到断点似乎并没有停止执行。
我有点假设它就像设置断点然后执行“测试|调试|当前上下文中的测试”一样简单……但这实际上从未达到我设置的断点。
我做错了什么还是这只是坏了?
谢谢,布兰登
我正在尝试在 Visual Studio 2008 中调试我的一些单元测试,并注意到断点似乎并没有停止执行。
我有点假设它就像设置断点然后执行“测试|调试|当前上下文中的测试”一样简单……但这实际上从未达到我设置的断点。
我做错了什么还是这只是坏了?
谢谢,布兰登
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.
就我而言System.Diagnostics.Debugger.Break()
,并不止于测试方法。
[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();
}
}
Microsoft 官方解决方法/kludge/zomg-I-can't-believe-they-can't-be-arsed-to-provide-this-after-4-years for MSTEST in VS2010、VS2008 和 VS2005 是添加System.Diagnostics.Debugger.Break()
到您要开始调试的单元测试。这适用于所有具有单元测试项目引用的调试符号的项目。
.NET 运行时会提示您转储到调试模式(或关闭正在执行的单元测试程序,或忽略调试行),并且(有时)允许您使用启动单元测试的 Visual Studio 实例来执行此操作。您始终可以从新的 VS 实例进行调试。一旦你点击了那System.Diagnostics.Debugger.Break()
行,所有其他断点都将处于活动状态并被命中(假设它们在执行堆栈中)。
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 :-)
检查以下内容:
[TestClass]
和[TestMethod]
?