最佳实践测试Asp.net MVC应用程序 [英] Best practices to test Asp.net MVC applications

查看:100
本文介绍了最佳实践测试Asp.net MVC应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


解决方案

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

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

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

希望有所帮助。

Whats the best practice to test an Asp.net MVC application?

解决方案

Choose your testing framework - I recommend xUnit.net.

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应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆