How Can I Add a Unit Test Project to an Existing MVC3 Application (from empty template)

妖精的绣舞 提交于 2019-12-05 09:16:06

问题


I created an MVC3 application from the Empty template so I couldn´t add a Visual Studio Unit test project to the solution.

I made some changes, added some controllers and now I want to try TDD so I need to add a framework for testing.

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.

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.

I am using 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?


回答1:


To add an empty Test project just go to File>Add>New Project choose Test subcategory > Test Project.




回答2:


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. Tools like MvcScaffolding will not work otherwise!




回答3:


File > Add > New Project > Test > Unit Test Project, which has name: "{ProjectName}.Tests". Next step's to add References, best way's to open your {ProjectName} -> References and r-click on System.Web. Mvc, look:

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, f.e: g:\disk\yourdll.dll = g:\disk\):

Next step's similar but add your {ProjectName}.dll by this way:

{ProjectName}.Tests -> References -> Add and Add {ProjectName}.dll:

Follow with presented steps and add references from your {ProjectName} to {ProjectName}.Tests.

Important dll:

  • System.Web.Mvc
  • System.Web.WebPages
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor
  • System.Web.Razor



回答4:


For your Solution do "File->New->Project". Select "Test->Unit Test Project". Then for a name enter "YourSolution.Tests" and press 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.



来源:https://stackoverflow.com/questions/4759860/how-can-i-add-a-unit-test-project-to-an-existing-mvc3-application-from-empty-te

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!