将 NUnit 添加到 ASP.NET MVC 测试框架的选项

发布于 2024-07-04 09:55:53 字数 432 浏览 8 评论 0原文

  • 我已经安装了 nUnit。
  • 我安装了VS2008团队版。
  • 我安装了 ASP.Net MVC Preview 4 (Codeplex)。

在创建新的 MVC 项目时,如何让 Visual Studio 向我显示 nUnit 作为测试框架? 此时我仍然只有 Microsoft 测试框架作为选择。

更新:我安装了nUnit 2.5,但仍然没有成功。 根据我在谷歌上的搜索,我似乎需要为测试项目创建模板,以便它们显示在“创建单元测试项目”中。 我本以为 nUnit、xUnit、MBUnit 等都可以使用模板。 等人。 另外,看起来我需要创建注册表项。 有人有任何其他信息吗?

更新:我通过研究确定了这个问题的答案,并将其发布在下面。

  • I have nUnit installed.
  • I have VS2008 Team Edition installed.
  • I have ASP.Net MVC Preview 4 (Codeplex) installed.

How do I make Visual Studio show me nUnit as a testing framework when creating a new MVC project? At this point I still only have the Microsoft Testing Framework as a choice.

Update: I installed nUnit 2.5, but still with no success. From what I've found Googling, it would seem I need to create templates for the test projects in order for them to be displayed in the "Create Unit Test Project". I would have thought that templates be readily available for nUnit, xUnit, MBUnit, et. al. Also, it looks like I need to created registry entries. Anybody have any additional information?

Update: I determined the answer to this through research and it's posted below.

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

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

发布评论

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

评论(4

一抹淡然 2024-07-11 09:55:54

伙计,他们的发行说明中列出了 VS 2008 项目模板。 我想这并不意味着他们已经将其与对话框集成了。

我使用 MbUnitGallio 一切都很顺利。 我必须安装 Gallio 和 MbUnit 的 Alpha,当我阅读发行说明中的​​上述内容时,我认为他们也实现了它。

请密切关注 nUnit 网站以获取未来的 alpha 版本。 我相信他们很快就会实施。 您还可以自己实现该功能并提交补丁。 :-)

Man, they have VS 2008 project template listed in their release notes. I guess that doesn't mean they have it integrated with the dialog yet.

I use MbUnit with Gallio and everything worked like a charm. I had to install an Alpha of Gallio and MbUnit and when I read the above in the release notes, I figured they implemented it also.

Just keep a look out on nUnit's site for future alpha releases. I am sure they'll have it implemented soon. You could also implement the feature yourself and submit a patch. :-)

梦行七里 2024-07-11 09:55:54

虽然他们没有与框架捆绑在一起,但这里有一个帖子链接,其中包含下载内容,可以自动为您创建“NUnit with moq”测试项目 NUnit with Moq

(在我的计算机上无法立即运行,W7 Beta,确保您使用提升的权限)

Although they do not have one bundled with the framework here is a link to post containing a download to automatically create the test project for "NUnit with moq" for you NUnit with Moq

(did not work right away on my computer, W7 Beta, make sure you use elevated permissions)

雪若未夕 2024-07-11 09:55:54

请安装 Testdriven.net 以将 NUnit 与 Visual Studio 集成。 MbUnit 和更高版本的 NUnit 还包含用于单元测试的项目模板。

您可以使用这些项目模板创建测试项目,然后引用您的 ASP.NET MVC 项目并能够测试其代码。

Do install Testdriven.net to integrate NUnit with Visual Studio. MbUnit and later versions of NUnit also contain project templates for unit tests.

You can use those project templates to create a test project and then reference to your ASP.NET MVC project and be able to test its code.

别低头,皇冠会掉 2024-07-11 09:55:53

经过大量研究和实验,我找到了答案。

  • 根据记录,当前版本的 nUnit 2.5 Alpha 似乎包含 Visual Studio 2008 中测试项目的模板。
  • 我按照指示进行操作 此处 描述了如何创建您自己的项目模板,然后添加适当的注册表项以允许您的模板出现在MVC 项目的“创建单元测试项目”对话框中的下拉框。

从较高的层面来看,您需要做的是:

  1. 创建一个项目
  2. 将其导出为模板(这会生成单个 ZIP 存档)
  3. 将其从本地用户的模板文件夹复制到 Visual Studio 主模板测试文件夹
  4. 执行 devenv .exe /setup
  5. 运行 regedit 并创建一些注册表项。

测试框架的选择就这么多了! 不过,公平地说,MVC 还不是测试版。

毕竟,我确实在下拉框中显示了选择的框架(NUnit)。 然而,仍有一些不足之处:

  • 虽然测试项目已正确创建,但它并没有自动具有对主 MVC 项目的项目引用。 当使用 Visual Studio Unit Test 作为测试项目时,它会自动执行此操作。
  • 我尝试打开生成的 ZIP 文件并编辑 MyTemplate.vssettings 文件以及 .csproj 项目文件,以纠正上述问题并调整事物的名称,使它们看起来更加用户友好。 由于某种原因,这不起作用。 生成的 ZIP 文件无法通过 WinZip 或 Win-Rar 更新 - 每个都表明存档已损坏。 不过,每个人都可以提取内容。 因此,我尝试更新提取的文件,然后重新创建 ZIP 文件。 Visual Studio 不喜欢它。

因此,我可能还应该阅读,其中讨论了为Visual Studio(在我上面链接的博客文章中也提到了。)不过我承认我很失望; 从所有关于 MVC 与其他测试框架配合良好等的讨论中,我认为注册第 3 方框架会更容易。

After a bunch of research and experimentation, I've found the answer.

  • For the record, the current release of nUnit 2.5 Alpha does not seem to contain templates for test projects in Visual Studio 2008.
  • I followed the directions here which describe how to create your own project templates and then add appropriate registry entries that allow your templates to appear in the drop-down box in the Create Unit Test Project dialog box of an MVC project.

From a high level, what you have to do is:

  1. Create a project
  2. Export it as a template (which results in a single ZIP archive)
  3. Copy it from the local user's template folder to the Visual Studio main template test folder
  4. Execute devenv.exe /setup
  5. Run regedit and create a few registry entries.

So much for the testing framework selection being easy! Although, to be fair MVC is not even beta yet.

After all that, I did get the framework of choice (NUnit) to show up in the drop down box. However, there was still a bit left to be desired:

  • Although the test project gets properly created, it did not automatically have a project reference to the main MVC project. When using Visual Studio Unit Test as the test project, it automatically does this.
  • I tried to open the ZIP file produced and edit the MyTemplate.vssettings file as well as the .csproj project file in order to correct the aforementioned issue as well as tweak the names of things so they'd appear more user friendly. This for some reason does not work. The ZIP file produced can not be updated via WinZip or Win-Rar -- each indicates the archive is corrupt. Each can extract the contents, though. So, I tried updating the extracted files and then recreating the ZIP file. Visual Studio did not like it.

So, I should probably read this as well which discusses making project templates for Visual Studio (also referenced in the blog post I linked to above.) I admit to being disappointed though; from all the talk about MVC playing well with other testing frameworks, etc, I thought that it'd be easier to register a 3rd party framework.

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