如何开始在 Visual Studio 项目中使用 Nunit?

发布于 2024-07-09 12:18:01 字数 150 浏览 6 评论 0原文

我想开始使用 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 技术交流群。

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

发布评论

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

评论(9

我的奇迹 2024-07-16 12:18:01

我喜欢在我的外部工具中添加 NUnit 的链接。

在“工具”->“外部工具”下添加 NUnit

Title: &NUnit
Command: <path to nunit>
Arguments $(ProjectFileName) /run
Initial directory: $(ProjectDir)

之后,您可以通过编译然后按 alt-t + n 快速运行它

I like to add a link to NUnit in my external tools.

Under Tools->External Tools add NUnit

Title: &NUnit
Command: <path to nunit>
Arguments $(ProjectFileName) /run
Initial directory: $(ProjectDir)

After that you can quickly run it by compiling then hitting alt-t + n

維他命╮ 2024-07-16 12:18:01

是的,基本上就是这样。 就我个人而言,我发现 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.

念三年u 2024-07-16 12:18:01

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)

心病无药医 2024-07-16 12:18:01

我在 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.

汹涌人海 2024-07-16 12:18:01

GUI 很好,但如果您经常运行测试,您可能会放弃它而选择更快/集成的运行器。

在任何情况下,您都可以选择如何运行测试:

  • NUnit.Gui.Exe - 您可以运行此&amp; 选择您的测试项目 dll 来运行测试。 当它打开时,它会在您构建时刷新,因此您可以使用 ALT-TAB 对其进行编辑。 重新运行你的tets。 我见过的另一种技术是将此应用程序设置为测试项目的启动程序。 然后将您的测试项目设置为启动项目并按 F5。
  • 下载& 使用 TestDriven.net。 这速度很快,并且允许您在坐在测试或解决方案资源管理器中的节点上时通过右键单击菜单运行测试。 这是我最常用的。 我将其映射到 CTRL+T 以便快速访问。
  • Resharper 也有一个测试运行程序。 这为您提供了 Visual Studio 内带有红/绿灯的 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:

  • NUnit.Gui.Exe -- you can run this & select your test project dll to run the tests. While it is open it will refresh when you build, so you can ALT-TAB to it & re-run your tets. Another technique I've seen is to set this application as the startup program for your test project. Then set your test project as the startup project and push F5.
  • Download & use TestDriven.net. This is fast and lets you run tests from a right click menu, while you're sitting on a test or at a node in the solution explorer. This is what I use mostly. I have it mapped to CTRL+T for quick access.
  • Resharper has a test runner as well. This gives you the GUI with red/green lights inside of visual studio. It also gives you a little icon next to each of your tests to quickly run them.
伴梦长久 2024-07-16 12:18:01

您可以使用此处提供的插件 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.

你是我的挚爱i 2024-07-16 12:18:01

您还应该记住,通过 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.

夜夜流光相皎洁 2024-07-16 12:18:01

您可以将它作为外部程序运行,但对我来说这不是很好。 我喜欢在 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.

野鹿林 2024-07-16 12:18:01

我将 nunit 控制台程序附加到构建后事件,因此每次构建项目时,测试都会运行,而不需要第三方工具(除了 NUnit 之外)。 我正在使用 Visual Studio 2010,但我非常确定您可以在 Visual Studio 2008 中实现相同的行为。

为此:

  1. 打开项目的属性窗口(包含测试的项目)
  2. 在构建后事件命令行中添加线:
    “C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console-x86.exe”
  3. "$(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:

  1. Open the project's properties window (the project containing the tests)
  2. In the Post-build event command line add the line:
    "C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console-x86.exe"
  3. "$(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.

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