我可以使 NUnit GUI 在断点/失败的测试中中断到 Visual Studio 调试器吗?

发布于 2024-09-10 19:30:10 字数 107 浏览 6 评论 0原文

使用 NUnit GUI 运行单元测试时,是否有办法:

  • 在测试内设置断点,
  • 或者在测试失败时中断到 Visual Studio 即时调试器?

When using the NUnit GUI to run unit tests, is there a way to either:

  • Set breakpoints inside the tests,
  • or break into the Visual Studio Just-in-Time debugger upon failure of a test?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

爱冒险 2024-09-17 19:30:11

您的第一个要求非常简单。将 VS 调试器附加到 NUnit GUI(工具 -> 附加到进程)并相应地设置断点。当附加调试器运行测试时,将命中断点。

第二个要求也很简单,但我还没有验证它是否有效(也就是说,我知道它会损坏,但我不知道它会损坏到用户代码多远)。当单元测试失败时,NUnit 框架会引发 NUnit.Framework.AssertionException。将调试器设置为在引发此异常时中断,并且您不需要在代码中设置断点。为此,请访问调试->异常...,然后选择添加...。选择公共语言运行时异常并输入 NUnit 异常的完整类型名称(包括命名空间)。最后,在原始例外屏幕中,选择新例外并单击抛出

同样,您需要使用附加的调试器来运行测试,以便它在引发异常时捕获。

Your first requirement is very straightforward. Attach the VS debugger to the NUnit GUI (Tools->Attach to Process) and set your breakpoints accordingly. When the tests run with the debugger attached, the breakpoints will be hit.

The second requirement is also straightforward, but I haven't verified it to work (that is, I know it will break, but I don't how far from user-code it will break). When a unit test fails, the NUnit framework raises an NUnit.Framework.AssertionException. Set the debugger to break when this exception is thrown, and you won't need to set breakpoints in your code. To do this, visit Debug->Exceptions..., then select Add.... Select Common Language Runtime Exception and enter the full typename (including namespace) of the NUnit exception. Finally, in the original exception screen, select your new exception and click Thrown.

Again, you will need to run your tests with the debugger attached in order for it to catch when the exceptions are thrown.

秋日私语 2024-09-17 19:30:11

将 Visual Studio 调试器附加到 NUnit 进程,然后在 NUnit GUI 中运行测试。

Attach the Visual Studio debugger to the NUnit process, and then run your tests in the NUnit GUI.

岁月静好 2024-09-17 19:30:11

如果将 Visual Studio 调试器附加到 nunit 进程并在 nunit 中执行测试,则将使用 Visual Studio 中的断点。

我不知道测试失败后如何做到这一点。

If you attach your Visual Studio debugger to the nunit process and execute your test in nunit, then the breakpoints in Visual Studio will be used.

I'm not aware of how this might be done upon failure of a test.

×眷恋的温暖 2024-09-17 19:30:11

除了在运行测试时附加到 NUnit 进程之外,您还可以临时添加到

Debugger.Launch()

SetUpFixture 或 TestFixtureSetUp 中,甚至添加到捕获预期异常的 try catch 中。

In addition to attaching to the NUnit process while running tests, you can temporarily add

Debugger.Launch()

either in a SetUpFixture or TestFixtureSetUp or even in a try catch where the anticipated exception is caught.

孤星 2024-09-17 19:30:10

不必担心附加到流程的麻烦。那很快就会变老。相反,请转到单元测试项目的属性,然后在“调试”选项卡中,将“启动外部程序:”设置为指向 nunit.exe,然后在“命令行参数”文本框中添加输出 dll 名称(例如 UnitTests .dll)

Don't bother with the hassle of attaching to a process. That gets old very quickly. Instead, go to the properties for your unit test project, and and the Debug tab, set "Start external program:" to point to nunit.exe, and add the output dll name in the "Command line arguments" text box (eg UnitTests.dll)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文