开发者

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.

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?


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


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!


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:

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

Then will open a new window, copy path to file:

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

And add your reference :-) to unit test project:

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

Then select Browse and go to Dictionary (remember to delete filename, f.e: g:\disk\yourdll.dll = g:\disk\):

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

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

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

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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜