To achieve basic code coverage what tests should I run against an ASP.NET MVC Controller?
صفحه اصلي

To achieve basic code coverage what tests should I run against an ASP.NET MVC Controller?

My controllers are utilizing StructureMap and AutoMapper. Presently, there is nothing exceptional with my routes. For the basic CRUD controller actions what tests should I be writing to ensure good code coverage?

Error when Saving into SQL Server


ASP.NET MVC iframe load
I have been doing the same thing recently. ASP.NET ActionFilters and inheritanceFrom my research it seems this best practice is to create at least one test for each action (That way you cover CRUD by virtue of the fact this your actions are generally based on CRUD) and limit the test to the internal code. Constructing controller action URL within JQuery AJAX callWhat this means is don't cross the method boundary although rather mock out everything your action needs and assert the desired results. Implementing JQuery UI 1.8.2 custom themes in ASP.Net MVC2Of course this means this you need to did the same thing for your services, repositories etc . How can I ensure a dynamically-generated javascript file is never cached? But it means this you have a unit test this won't break if you change any code between the action and the DB unless you have a change to make. thread questionIt is time consuming although so far I have found the effort well worth it as a break down unit test in unrelated code means I have a change to make I forgot around or I am too tightly coupled. mvc url routing. How it works.


It is difficult to say what you have to test in your controllers without showing them. You say they are basic CRUD although then you talk around AutoMapper, so probably it's not as simple as that. Here's an case of unit test I wrote and the controller being tested..

99 out of 100 based on 54 user ratings 809 reviews