Freigeben über


Unit Testing ASP.NET MVC Routes

Two things I always encourage customers to do are;

  1. Always delete the default route pattern after a File –> New project. This helps you focus on designing your routes throughout your site, and helps reduce SEO-unfriendly routes etc.
  2. Always unit test your routing table.

For number two, this is because it is so easy to have a route that looks like this;

/products/{productname}/{action}

… and then a developer comes along and adds a new route higher up the routing table that looks like this;

/products/{category}/{subcategory}

Hey presto, your website is broken. No-one can navigate to the {productname} pattern (assuming you have no other route validation going on). For this reason it is essential to unit test your routing table for any website, especially if it’s already live and you’re modifying it and adding functionality over time, because you could easily take down a whole piece of functionality. Remember to apply all the routes from every Area in your application during testing.

Rather than write up how to go about doing this unit testing, let me point you at some great resources;

Have a read, and write those tests today Smile

Comments