如何将单元测试项目添加到现有MVC3应用程序(从空模板)

时间:2023-01-27 10:30:21

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?

初学者怎么样?

4 个解决方案

#1


15  

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

要添加空的测试项目,只需转到文件>添加>新建项目,选择测试子类别>测试项目。

#2


15  

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!

测试项目的命名非常重要!如果您的MVC项目名为“MyProject”,则您的测试项目必须命名为“MyProject.Tests”才能连接它们。像MvcScaffolding这样的工具不会起作用!

#3


10  

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:

文件>添加>新建项目>测试>单元测试项目,其名称为“{ProjectName} .Tests”。下一步是添加引用,最好的方法是打开你的{ProjectName} - >引用,然后在System.Web上单击r。 Mvc,看:

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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

然后会打开一个新窗口,复制路径到文件:

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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

并将您的参考:-)添加到单元测试项目中:

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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

然后选择Browse并转到Dictionary(记得删除filename,f.e:g:\ disk \ yourdll.dll = g:\ disk \):

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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:

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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

按照提供的步骤进行操作,并将{ProjectName}中的引用添加到{ProjectName} .Tests。

Important dll:

重要的dll:

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

#4


1  

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.

对于您的解决方案,请执行“文件 - >新建 - >项目”。选择“测试 - >单元测试项目”。然后输入“YourSolution.Tests”并按OK。接下来添加对YourSolution的引用:在“YourSolution.Tests-> References”上单击鼠标右键并浏览到“解决方案”,确保为YourSolution选中了一个复选框,然后按“确定”。

#1


15  

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

要添加空的测试项目,只需转到文件>添加>新建项目,选择测试子类别>测试项目。

#2


15  

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!

测试项目的命名非常重要!如果您的MVC项目名为“MyProject”,则您的测试项目必须命名为“MyProject.Tests”才能连接它们。像MvcScaffolding这样的工具不会起作用!

#3


10  

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:

文件>添加>新建项目>测试>单元测试项目,其名称为“{ProjectName} .Tests”。下一步是添加引用,最好的方法是打开你的{ProjectName} - >引用,然后在System.Web上单击r。 Mvc,看:

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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

然后会打开一个新窗口,复制路径到文件:

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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

并将您的参考:-)添加到单元测试项目中:

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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

然后选择Browse并转到Dictionary(记得删除filename,f.e:g:\ disk \ yourdll.dll = g:\ disk \):

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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:

如何将单元测试项目添加到现有MVC3应用程序(从空模板)

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

按照提供的步骤进行操作,并将{ProjectName}中的引用添加到{ProjectName} .Tests。

Important dll:

重要的dll:

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

#4


1  

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.

对于您的解决方案,请执行“文件 - >新建 - >项目”。选择“测试 - >单元测试项目”。然后输入“YourSolution.Tests”并按OK。接下来添加对YourSolution的引用:在“YourSolution.Tests-> References”上单击鼠标右键并浏览到“解决方案”,确保为YourSolution选中了一个复选框,然后按“确定”。