问题
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