visual-studio 将 NUnit 添加到 ASP.NET MVC 测试框架的选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding NUnit to the options for ASP.NET MVC test framework
提问by Peter Meyer
- I have nUnit installed.
- I have VS2008 Team Edition installed.
- I have ASP.Net MVC Preview 4 (Codeplex) installed.
- 我安装了 nUnit。
- 我安装了 VS2008 团队版。
- 我安装了 ASP.Net MVC Preview 4 (Codeplex)。
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.
在创建新的 MVC 项目时,如何让 Visual Studio 向我显示 nUnit 作为测试框架?在这一点上,我仍然只有 Microsoft 测试框架作为选择。
Update:I installed nUnit 2.5, but still with no success. From what I've found Googling, it would seem I need to createtemplates 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?
更新:我安装了 nUnit 2.5,但仍然没有成功。从我发现的谷歌搜索来看,似乎我需要为测试项目创建模板,以便它们显示在“创建单元测试项目”中。我原以为模板很容易用于 nUnit、xUnit、MBUnit 等。阿尔。另外,看起来我需要创建注册表项。有人有任何额外的信息吗?
Update:I determined the answer to this through research and it's posted below.
更新:我通过研究确定了这个问题的答案,并将其发布在下面。
采纳答案by Peter Meyer
After a bunch of research and experimentation, I've found the answer.
经过大量的研究和实验,我找到了答案。
- For the record, the current release of nUnit 2.5 Alpha does notseem to contain templates for test projects in Visual Studio 2008.
- I followed the directions herewhich 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 Projectdialog box of an MVC project.
- 作为记录,当前版本的 nUnit 2.5 Alpha似乎不包含 Visual Studio 2008 中测试项目的模板。
- 我遵循了此处的说明,其中描述了如何创建您自己的项目模板,然后添加适当的注册表项,以允许您的模板出现在MVC 项目的“创建单元测试项目”对话框的下拉框中。
From a high level, what you have to do is:
从高层次来看,你需要做的是:
- Create a project
- Export it as a template (which results in a single ZIP archive)
- Copy it from the local user's template folder to the Visual Studio main template test folder
- Execute devenv.exe /setup
- Run regeditand create a few registry entries.
- 创建项目
- 将其导出为模板(生成单个 ZIP 存档)
- 将其从本地用户的模板文件夹复制到 Visual Studio 主模板测试文件夹
- 执行devenv.exe /setup
- 运行regedit并创建一些注册表项。
So much for the testing framework selection being easy! Although, to be fair MVC is not even beta yet.
测试框架选择就这么简单!虽然,公平地说 MVC 还不是测试版。
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:
毕竟,我确实让选择的框架 (NUnit) 显示在下拉框中。但是,仍有一些不足之处:
- 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 Testas 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.
- 尽管正确创建了测试项目,但它并没有自动拥有对主 MVC 项目的项目引用。使用 Visual Studio 单元测试作为测试项目时,它会自动执行此操作。
- 我尝试打开生成的 ZIP 文件并编辑 MyTemplate.vssettings 文件以及 .csproj 项目文件,以更正上述问题并调整事物的名称,使它们看起来更加用户友好。这出于某种原因不起作用。生成的 ZIP 文件无法通过 WinZip 或 Win-Rar 更新——每个都表明存档已损坏。不过,每个人都可以提取内容。因此,我尝试更新提取的文件,然后重新创建 ZIP 文件。Visual Studio 不喜欢它。
So, I should probably read thisas 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.
所以,我可能也应该阅读这篇文章,其中讨论了为 Visual Studio 制作项目模板(也在我上面链接的博客文章中引用)。不过我承认我很失望;从所有关于 MVC 与其他测试框架等的良好配合的讨论中,我认为注册 3rd 方框架会更容易。
回答by Dale Ragan
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.
伙计,他们的发行说明中列出了 VS 2008 项目模板。我想这并不意味着他们已经将它与对话框集成了。
I use MbUnitwith Gallioand 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.
我将MbUnit与Gallio一起使用,一切都很顺利。我必须安装一个 Alpha 的 Gallio 和 MbUnit,当我在发行说明中阅读上述内容时,我认为他们也实现了它。
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. :-)
只需在 nUnit 的站点上查看未来的 alpha 版本即可。我相信他们很快就会实施。您也可以自己实现该功能并提交补丁。:-)
回答by smaclell
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
虽然他们没有与框架捆绑在一起,但这里有一个包含下载的帖子链接,可以为您自动为“NUnit with moq”创建测试项目NUnit with Moq
(did not work right away on my computer, W7 Beta, make sure you use elevated permissions)
(在我的电脑 W7 Beta 上无法立即使用,请确保您使用提升的权限)
回答by Jon Limjap
Do install Testdriven.netto integrate NUnit with Visual Studio. MbUnit and later versions of NUnit also contain project templates for unit tests.
请安装Testdriven.net以将 NUnit 与 Visual Studio 集成。MbUnit 和更高版本的 NUnit 还包含用于单元测试的项目模板。
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.
您可以使用这些项目模板创建一个测试项目,然后引用您的 ASP.NET MVC 项目并能够测试其代码。

