ASP.NET MVC Testing Tips and Tricks
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?
One Suggestion: SpecsFor.Mvc!
by
Matt Honeycutt
Re: One Suggestion: SpecsFor.Mvc!
by
Roopesh Shenoy
One concern I have is how do you reuse these test-steps? One of the greatest features in BDD frameworks seems to be that you can reuse your test steps in multiple test cases making them more efficient. Look here for instance - nbehave.codeplex.com/wikipage?title=Using%20NBe....
Educational Content
Intro to CLP with core.logic
Ryan Senior Jun 18, 2013
Spock: A Highly Logical Way To Test
Howard Lewis Ship Jun 18, 2013
Java Garbage Collection Distilled
Martin Thompson Jun 17, 2013
C++11 The Future is Here
Bjarne Stroustrup Jun 16, 2013
The Big Data Revolution
Claudia Perlich Jun 16, 2013




Hello stranger!
You need to Register an InfoQ account or Login to post comments. But there's so much more behind being registered.Get the most out of the InfoQ experience.
Tell us what you think