5

我正在尝试在 Visual Studio 2008 中调试我的一些单元测试,并注意到断点似乎并没有停止执行。

我有点假设它就像设置断点然后执行“测试|调试|当前上下文中的测试”一样简单……但这实际上从未达到我设置的断点。

我做错了什么还是这只是坏了?

谢谢,布兰登

4

5 回答 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.

于 2009-08-13T17:25:00.380 回答
1

就我而言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();

   } 
}
于 2011-10-03T10:18:22.817 回答
0

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()行,所有其他断点都将处于活动状态并被命中(假设它们在执行堆栈中)。

于 2010-06-17T22:05:32.690 回答
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 :-)

于 2009-08-13T17:30:25.437 回答
0

检查以下内容:

  • 测试是否标有[TestClass][TestMethod]
  • 您正在运行调试或发布模式构建吗?(除非确实如此,否则不会有很大的不同)调试更好。
  • 您是在编译时进行优化还是不进行优化?没有更好
  • 尝试运行解决方案中的所有测试以检查是否遇到断点
  • 最后,也许你有错误,这就是你没有点击代码的原因?
于 2009-07-07T08:39:40.807 回答