Can an ASP.NET MVC project with attribute routing be tested? Can an ASP.NET MVC project with attribute routing be tested? asp.net asp.net

Can an ASP.NET MVC project with attribute routing be tested?


Good question, and I think that the answer is that little or no thought was given to testing routes in the design of this part of the framework. There may be ways to test routes, but they will be indirect, undocumented and prone to break when a new version of MVC ships.

I have a blog post here on my experiences on the topic. I also suggest that you also campaign for better testability in ASP vNext in the public issue tracker.


During a daily stand-up, a colleague mentioned he was integration testing via an in-memory web server. Intrigued, he showed me how and I was amazed, learnt something :-)

You can new-up an HttpServer instance and have it read your config and then invoke the server instance. I have not tried it, but I see no reason why this wouldn't enumerate your routes and code needing proper config will all work.

This SO question is related and may help in how to set this up:

How does the In-Memory HttpServer know which WebAPI project to host?