[英]Testing a MVC5 Web application
I am very new to MVC and I am trying to test my application.我对 MVC 很陌生,我正在尝试测试我的应用程序。 When I created the application I did not select add test project.
创建应用程序时,我没有选择添加测试项目。 I have added a unit test project and am trying to test a controller however when I enter the controller name the type or namespace cannot be found and asks if I am missing a assembly reference.
我添加了一个单元测试项目并试图测试一个控制器,但是当我输入控制器名称时,找不到类型或命名空间并询问我是否缺少程序集引用。 Any help would be greatly appreciated
任何帮助将不胜感激
Thanks谢谢
Here is how to do it, step by step. 这是逐步进行的方法。
In my solution, I have MyEmailer.UI
is a MVC
project, then I add a test project named MyEmailer.Test
. 在我的解决方案中,我有
MyEmailer.UI
是一个MVC
项目,然后添加了一个名为MyEmailer.Test
的测试项目。 Now, to call HomeContrller
from MyEmailer.UI
in MyEmailer.Test
, we do it like this: 现在,要从
MyEmailer.UI
中的MyEmailer.Test
调用HomeContrller
,我们需要这样做:
Right click
References
in your test project ( MyEmailer.Test
), choose Add Reference
. 右键单击
References
在您的测试项目( MyEmailer.Test
),选择Add Reference
。
On the left side, choose
Solution --> Project
. 在左侧,选择
Solution --> Project
。 On the right side, check your MVC
project ( MyEmailer.UI
). 在右侧,检查您的
MVC
项目( MyEmailer.UI
)。
Notice on the
References
, add a library called System.Web.Mvc
. 注意,在
References
,添加了一个名为System.Web.Mvc
的库。 Then, in your UnitTest.cs
, add the using
. 然后,在您的
UnitTest.cs
,添加using
。
Now, you can call your controllers from your test project. 现在,您可以从测试项目中调用控制器。
您必须将MVC项目的引用添加到测试项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.