ASP.NET MVC Tip #6 – Code Snippets for Quickly Testing Routes

Thursday, February 21, 2008


You want to write some tests for your route configuration, but you hate typing…


We can create some VS Code Snippets to generate most of the tests for you.  While messing around with Kigg, I got the idea to create some snippets to make writing the route tests a little simpler.  These snippets assume you are using MbUnit and Rhino Mocks.  You also need to have your references and imports set up correctly.  With these snippets you can create a full route test fixture with just two commands:

mvcrtestfix – generate the test fixture class for your routes

mvcrtest – generate the test for a specific route

The route test will generate code to check for the correct controller and action.  You can add additional asserts to check that values were passed in.  You can download a zip file with both snippets here.  Then just import them from VS Code Snippet Manager menu item and you’ll have access to it in your IDE shortcuts.


And here’s some of the code it will generate for you with placeholders for you to edit.

Hope this helps…. 

Leave a Reply