Integration test and unit test (WEB API mvc 4)

时光怂恿深爱的人放手 提交于 2019-12-10 14:29:17

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/11927587/integration-test-and-unit-test-web-api-mvc-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!