请告诉我测试一个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应用程序
发布评论