[英]How Can I Add a Unit Test Project to an Existing MVC3 Application (from empty template)
I created an MVC3 application from the Empty template so I couldn´t add a Visual Studio Unit test project to the solution. 我从Empty模板创建了一个MVC3应用程序,因此我无法在解决方案中添加Visual Studio Unit测试项目。
I made some changes, added some controllers and now I want to try TDD so I need to add a framework for testing. 我做了一些更改,添加了一些控制器,现在我想尝试TDD,所以我需要添加一个框架进行测试。
But I can´t see how I can do that. 但是我看不出我能做到这一点。
I want some way where I can create my test project right in the Solution Explorer, for example "website.Test" with some basic folders and files. 我想在某种方式,我可以在解决方案资源管理器中创建我的测试项目,例如“website.Test”与一些基本的文件夹和文件。
I saw here some questions about how to add Unit tests, but those were with xUnit.net or NUnit and I want the original VS test framework. 我在这里看到了一些关于如何添加单元测试的问题,但是那些是xUnit.net或NUnit,我想要原始的VS测试框架。
I am using Visual Studio 2010 Professional. 我正在使用Visual Studio 2010 Professional。
I am also interested to know what others think about the 3rd-party unit test frameworks, are they better? 我也有兴趣知道其他人对第三方单元测试框架的看法,他们更好吗?
What about for beginners? 初学者怎么样?
要添加空的测试项目,只需转到文件>添加>新建项目,选择测试子类别>测试项目。
The naming of the test-project is significant! 测试项目的命名非常重要! If your MVC-project is named "MyProject" your test-project has to be named "MyProject.Tests" in order to connect both of them.
如果您的MVC项目名为“MyProject”,则您的测试项目必须命名为“MyProject.Tests”才能连接它们。 Tools like MvcScaffolding will not work otherwise!
像MvcScaffolding这样的工具不会起作用!
File > Add > New Project > Test > Unit Test Project
, which has name: "{ProjectName}. Tests ". File > Add > New Project > Test > Unit Test Project
,其名称为“{ProjectName}。 测试 ”。 Next step's to add References, best way's to open your {ProjectName} -> References and r-click on System.Web. 下一步是添加引用,最好的方法是打开你的{ProjectName} - >引用,然后在System.Web上单击r。 Mvc, look:
Mvc,看:
Then will open a new window, copy path to file: 然后会打开一个新窗口,复制路径到文件:
And add your reference :-) to unit test project : 并将您的参考:-)添加到单元测试项目中 :
Then select Browse
and go to Dictionary (remember to delete filename, fe: g:\\disk\\yourdll.dll
= g:\\disk\\
): 然后选择
Browse
并转到Dictionary (记得删除filename,fe: g:\\disk\\yourdll.dll
= g:\\disk\\
):
Next step's similar but add your {ProjectName}.dll by this way: 下一步是类似的,但通过这种方式添加您的{ProjectName} .dll:
{ProjectName}.Tests -> References -> Add
and Add {ProjectName}.dll: {ProjectName}.Tests -> References -> Add
and Add {ProjectName} .dll:
Follow with presented steps and add references from your {ProjectName} to {ProjectName}.Tests. 按照提供的步骤添加{ProjectName}到{ProjectName} .Tests的引用。
Important dll: 重要的dll:
For your Solution do "File->New->Project". 对于您的解决方案,请执行“文件 - >新建 - >项目”。 Select "Test->Unit Test Project".
选择“测试 - >单元测试项目”。 Then for a name enter "YourSolution.Tests" and press OK.
然后为名称输入“YourSolution.Tests”并按OK。 Next add a reference to YourSolution: on "YourSolution.Tests->References" right click and browse to Solutions, make sure that there is a check box selected for YourSolution and press Ok.
接下来添加对YourSolution的引用:在“YourSolution.Tests-> References”上单击鼠标右键并浏览到“解决方案”,确保为YourSolution选中了一个复选框,然后按“确定”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.