There are several components in an ASP.NET MVC 3 web app – models, controllers, route-handlers, views, html-helpers, client-side code etc. Most of these can be unit-tested, others need integration tests, and several good practices can help you keep your tests more maintainable and avoid making them brittle.
Here are some resources -
- Along with your actions you can also scaffold the unit tests with MvcScaffolding.
- Use custom HTML Helpers instead of writing a lot of logic in your views – html helpers can be unit tested easily. Also avoid hard-coding html elements when testing custom HTML-helpers.
- Use BDD frameworks like Specflow to write end-to-end acceptance tests
- It is easy to break existing routes when adding a new route higher up the routing table – you can unit test your routing table to avoid this
- Turn on compilation for your views. This is not exactly unit testing, but it does help in identifying bugs that would otherwise be seen only on runtime.
- Use WaTiN for testing your UI, if they are not very volatile. Alternatively, you can also make your integration tests a bit flexible in accommodating pure UI design changes by using Page Objects.
- Use a JS testing framework like Jasmine to test your JavaScript.
Do you have any other testing tips you want to share for testing ASP.NET MVC applications?