Unit testing ASP.NET MVC Controller methods through concrete class or interface
I'm writing some unit tests for some controller methods in my project and am wondering whether to test against the controller class itself or an interface of that controller.
Should I be creating an interface for each controller and run my unit 开发者_运维问答tests against that?
You should test against the concrete conroller as that is where your site specifit code is occuring. You should inject service or data access code into the controller via their interfaces so that you can mock out the data access layer.
Do you have a need to treat your controllers as interfaces (quite unlikely I would of thought)? if so test against that. If not, then directly test against the controllers.
精彩评论