集成测试和单元测试(WEB API MVC 4) [英] Integration test and unit test (WEB API mvc 4)

查看:181
本文介绍了集成测试和单元测试(WEB API MVC 4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎么做集成测试和单元测试在APIController做测试的相关性?我怎么能嘲笑库,同时创造了集成测试中的WebRequest所以它不会使一个实际的数据库查询?

how does the integration test and unit test relevant in doing testing on APIController? and how can i mock the repository while creating the webrequest in the integration test so it does not make an actual query to the database?

推荐答案

您可以使用自托管功能启动控制器,并使用 OpenAsync()ContinueWith(T => {/ * ... * /})函数来运行你的测试。您将要覆盖 Configuration.DependencyResolver 并重写 IHttpControllerActivator ,以便您可以指定自己的mock实现(例如,你可以使用Ninject来检索已经与模拟实现息息相关的特殊控制器)。

You can use the Self Hosting functionality to start up the controllers and use the OpenAsync().ContinueWith(t => { /* ... */ }) function to run your tests. You'll want to override the Configuration.DependencyResolver and override the IHttpControllerActivator so that you can specify your own mock implementation (e.g. you can use Ninject to retrieve the specific controller already bound up with a mock implementation).

这篇关于集成测试和单元测试(WEB API MVC 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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