在 VS 2008 中调试单元测试用例
我正在尝试在 Visual Studio 2008 中调试一些单元测试,并注意到断点似乎并没有停止执行。
我认为这就像设置断点然后执行“测试|调试|在当前上下文中测试”一样简单......但这实际上从未达到我设置的断点。
我做错了什么还是这只是坏了?
谢谢, 布兰登
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我遇到了同样的问题,直到我先手动附加到 aspnet_wp.exe 进程,然后单击“调试测试”按钮。 然后我的断点终于被命中了。
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()
不会停止于测试方法。In my case
System.Diagnostics.Debugger.Break()
doesn't stop at testing method.如果您使用 nUnit,则必须使用
要测试的 DLL 启动 Nunit。
然后在 Visual Studio 中转到
工具-> 附加到进程
选择您的 nunit 进程并单击“附加”,然后它将在您的所有断点处停止,
玩得开心:-)
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 :-)
Microsoft 官方 workaround/kludge/zomg-I-can't- believe-they -can't-be-arsed-to-provide-this-after-4-years 对于 VS2010、VS2008 和 VS2005 中的 MSTEST 是添加
System.Diagnostics.Debugger.Break() code> 到您想要开始调试的单元测试。 这适用于具有单元测试项目引用的调试符号的所有项目。
.NET 运行时将提示您转储到调试模式(或关闭正在执行的单元测试程序,或忽略调试行),并且(有时)允许您使用启动单元测试的 Visual Studio 实例来执行此操作。 您始终可以从新的 VS 实例进行调试。 一旦到达 System.Diagnostics.Debugger.Break() 行,所有其他断点都将处于活动状态并被命中(假设它们位于执行堆栈中)。
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).检查以下内容:
[TestClass]
和[TestMethod]
?Check the following:
[TestClass]
and[TestMethod]
?