最佳实践测试Asp.net MVC应用程序

编程入门 行业动态 更新时间:2024-10-24 21:30:19
本文介绍了最佳实践测试Asp MVC应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请告诉我测试一个Asp MVC应用程序的最佳做法?

解决方案

选择您的测试框架 - 我推荐的 xUnit 。

使用接口​​中分离出的类和使用构造函数注入在控制器来满足相关性。在测试中,通嘲笑用嘲弄的框架,你的控制器 - 我建议起订量

在运行的网站,而不是测试,无论是对你的控制器,调用其他构造,并通过你的真实的接口的实现默认构造;或使用依赖注入(DI)容器自动做到这一点 - 我建议 StructureMap

希望有所帮助。

Whats the best practice to test an Asp MVC application?

解决方案

Choose your testing framework - I recommend xUnit.

Decouple your classes using interfaces and use constructor injection in your controllers to satisfy dependencies. In your tests, pass mocks to your controllers using a mocking framework - I recommend MoQ.

When running the web site rather than tests, either have default constructors on your controllers that call the other constructors and pass your real implementations of your interfaces; or use a Dependency Injection (DI) container to do it automatically - I recommend StructureMap.

Hope that helps.

更多推荐

最佳实践测试Asp.net MVC应用程序

本文发布于:2023-05-29 23:05:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/355037.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   测试   net   Asp   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!