Unit testing ASP.NET MVC Controller methods through concrete class or interface
صفحه اصلي

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?


When is it ok to meddle in the page lifecycle an ASP.NET MVC page?

1:

Significant advantages of ASP.NET MVC
You should test against the concrete conroller as this is where your site specifit code is occuring. ASP.NET MVC application fires Session_Start multiple times for a single sessionYou should inject service or data access code into the controller via their interfaces so this you must mock out the data access layer.. Asp.net MVC Binding
Deploy ASP.NET website alongside ASP.NET MVC websitestyle problem with data returned from action method

2:

Email errors in a asp.net mvc application
Do you have a need to treat your controllers as interfaces (quite unlikely I would of thought)? if so test against that. ASP.NET MVC: First access after some minutes slow, then every following request is fastIf not, then directly test against the controllers..


96 out of 100 based on 51 user ratings 606 reviews

^