如何开始在 Visual Studio 项目中使用 Nunit?
我想开始使用 Nunit(最后),我正在使用 Visual Studio 2008。
是否像将 Nunit 导入到我的测试项目中一样简单?
我记得看到过 NUnit 的 GUI,除了直观地显示通过/失败之外,它与单独的测试项目所做的事情是否完全相同?
I want to start using Nunit (finally), I am using Visual Studio 2008.
Is it as simple as importing Nunit into my test project?
I remember seeing a GUI for NUnit, does that do the exact same thing that a separate test project would do, except show you the pass/fail visually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
我喜欢在我的外部工具中添加 NUnit 的链接。
在“工具”->“外部工具”下添加 NUnit
之后,您可以通过编译然后按 alt-t + n 快速运行它
I like to add a link to NUnit in my external tools.
Under Tools->External Tools add NUnit
After that you can quickly run it by compiling then hitting alt-t + n
是的,基本上就是这样。 就我个人而言,我发现 ReSharper 附带的单元测试运行器非常出色 - 而且该工具本身非常值得获得许可感觉。 或者还有TestDriven.NET。
拥有一个单独运行 nunit-gui 或 nunit-console 的测试项目固然很好,但您确实希望整个单元测试体验尽可能无缝。 编写和运行测试越容易,您就越有可能这样做——这是一件非常好的事情。 不要低估由于用户体验稍差、在窗口之间切换等而逐渐积累的挫败感。
Yes, that's basically it. Personally I find the unit test runner which comes with ReSharper to be excellent - and the tool itself is well worth the licence feel. Alternatively there's TestDriven.NET.
Having a test project which runs nunit-gui or nunit-console separately is all very well, but you really want the whole unit testing experience to be as seamless as possible. The easier it is to write and run tests, the more likely you are to do it - which is a very good thing. Don't underestimate the gradual build-up of frustration due to a slightly poorer user experience, flipping between windows etc.
NUnit 不在 Visual Studio 2008 中。它有一个控制台或图形用户界面 (gui),可以在 VS2008 外部运行,也可以附加到 VS2008 进程进行调试。
如果你确实想要 VS2008 中的某些东西,你需要有像 ReSharper 这样的第三方插件。
编辑:过去已经回答过(不适用于 VS2008,但仍然相关)
NUnit is something that isn't inside Visual Studio 2008. It does have a console OR a graphical user interface (gui) that can be run both outside VS2008 OR can be attached to the process of VS2008 for debugging.
If you do want something inside VS2008 you need to have a third party pluging like ReSharper.
Edit: This has been answered in the past (not for VS2008 specificly but still relevant)
我在 VS2005 中使用了 TestDriven.NET,它改变了我开发和测试代码的方式。
您可以对任何类、模块、项目或解决方案运行所有测试。 您还可以在调试器中运行测试,这对于诊断和修复出现的问题非常有用。
I've used TestDriven.NET with VS2005, and it has changed how I develop and test code.
You can run all of the tests on any class, module, project, or solution. You can also run a test in the debugger, which is tremendously useful to diagnose and fix issues when they crop up.
GUI 很好,但如果您经常运行测试,您可能会放弃它而选择更快/集成的运行器。
在任何情况下,您都可以选择如何运行测试:
The GUI is nice, but if you run your tests often, you'll probably abandon it for a faster/integrated runner.
In any case, you have some options on how to run your tests:
您可以使用此处提供的插件 NUnitForVS: http://www.codeplex.com/NUnitForVS
这会将测试运行和结果集成到 VS 2008 IDE 中。 我们已经使用它几个月了,它对我们来说效果很好。
You can use the plugin NUnitForVS that is available here: http://www.codeplex.com/NUnitForVS
This integrates the test running and results in your VS 2008 IDE. We've been using it for a couple of months and it's working well for us.
您还应该记住,通过 VS 2008 professional,您可以使用以前仅在团队版本中可用的 MS Unit 测试工具。
You should also remember that with VS 2008 professional you can use the MS Unit testing tool that was previously only available in the team versions.
您可以将它作为外部程序运行,但对我来说这不是很好。 我喜欢在 VS 中开始测试。 因此,如果您有 ReSharpe,您可以转到“工具”->“工具”->“ReSharpe”。 选项-> 环境-> 键盘并设置 ReSharper_UnitTest_ContextRun 的热键。 我将其设置为 Ctrl + t。
You can run it as external program, but as for me it is not very nice. I like, when test starts within the VS. So, if you have ReSharpe you can go to Tools -> Options -> Environment -> Keyboard and set the hot key for ReSharper_UnitTest_ContextRun. I set it to Ctrl + t.
我将 nunit 控制台程序附加到构建后事件,因此每次构建项目时,测试都会运行,而不需要第三方工具(除了 NUnit 之外)。 我正在使用 Visual Studio 2010,但我非常确定您可以在 Visual Studio 2008 中实现相同的行为。
为此:
“C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console-x86.exe”
"$(TargetDir)$(TargetFileName)"
构建项目,输出应写入输出窗口(构建)。 选择 x86 版本的控制台运行程序非常重要。
I attach my nunit console program to the Post-build event so every time I build my project the tests are run without the need for third party tools (apart from NUnit). I'm using Visual Studio 2010, but I am pretty sure you can achieve the same behaviour in Visual Studio 2008.
To do this:
"C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console-x86.exe"
"$(TargetDir)$(TargetFileName)"
Build the project and the output should be written to the Ouptput window (Build). It's important to choose the x86 version of the console runner.