如何让 Visual Studio 将异常抛出到 NUnit gui 中?
我是 C# 新手,对 NUnit 和 Visual Studio 关于异常的交互方式感到困惑。
之前使用它时,我记得异常被抛出到 NUnit Gui 的“错误和失败”选项卡中,使测试变成红色 - 这就是我现在需要的。
现在,即使 Assert.Fail 也会将我返回到 VS 窗口。
我的设置是:
- VS 2010 Express,NUnit 2.5.10
- 主项目是“类库”输出
- Launcher 项目是一个启动项目,“Windows 应用程序”输出并引用
- 我运行的 主项目Visual Studio 中的测试按“调试”(这将打开 NUnit GUI 窗口)
- 启动器代码:
命名空间启动器 { 类启动器 { [STA线程] 静态无效主(字符串[]参数) { NUnit.Gui.AppEntry.Main(new[] { "MainProject.dll" }); } } }
我知道我可以打开 NUnit,然后打开我的 dll,它会在 NUnit 窗口内显示异常。
我想要的是按“调试”并让 NUnit 执行我选择的测试,将异常抛出到 NUnit 窗口中,并使我能够设置断点 - 这以前有效!
I'm new to C# and I am confused with the way NUnit and Visual Studio interact regarding exceptions.
From using it before, I remember that exceptions were thrown into the NUnit Gui "Errors and failures" tab, making the tests red - that is what I need now.
Now even Assert.Fail returns me to the VS window.
My setup is:
- VS 2010 Express, NUnit 2.5.10
- Main project is a 'Class Library' output
- Launcher project is a starup project, 'Windows Application' output and has a reference to the main project
- I run the tests from Visual Studio pressing 'debug' (this brings up the NUnit GUI window)
- Launcher code:
namespace Launcher { class Launcher { [STAThread] static void Main(string[] args) { NUnit.Gui.AppEntry.Main(new[] { "MainProject.dll" }); } } }
I know that I can open NUnit and then my dll and it will show exceptions inside NUnit window.
What I want is to press Debug and have NUnit to execute tests that I select, throw exceptions into NUnit window and make me able to set breakpoints - that worked before!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
打开Nunit,
转到文件 -->打开项目
导航到单元测试项目的 .dll,这应该会打开所有测试。
从这里您可以运行所有测试等。
您可以设置 nunit 在每次重建项目时运行测试(因此 ctrl-shift-b)。无需总是按下调试按钮。
如果你想调试你的测试,
(在vs2010中),进入调试-->附加到进程 -->选择nunit-agent.exe,
这应该可以让你达到断点。
Open up Nunit,
Go to File --> Open project
Navigate to the .dll of your unit test project, this should open up all your tests.
From here you can run all the test etc.
You can setup nunit to run test everytime you rebuild your project (so ctrl-shift-b). No need to always press the debug button.
If you want to debug your test,
(in vs2010), go to debug --> attach to process --> select nunit-agent.exe,
that should allow you to hit your breakpoints.