Skip navigation

Tag Archives: testing

I’ve started my first MVC project recently, and after getting a few actions working, I started running into problems.  The URL I was generating weren’t routing to the action methods I intended.  This isn’t entirely unexpected given that not only is this my first MVC project, it’s my first foray into .NET, OO, C#, Linq, IoC, TDD, the list goes on. 

So I’d get an action on the controller looking good, then the View, but the output URL would have querystring params.  So I’d add or change one of the routes until it looked like I intended, but then another URL would break, inserting the name of the controller prior to the action.

I had no tests at this point and was pretty frustrated with the process at that point.  So I decided to go to The Bible and get some tests around the inbound routes.  Blam, red all up in yo face courtesy of NUnit. 

Now that I had a full set of tests for the URLs I intended I could tweak the routes with an actual direction, not just aimless wandering.  Within minutes all tests passed and all routes were behaving on the site itself.  Not to mention I feel more confident going forward.

So, yeah, obvious to people that have been doing this for a while, but it’s really enlightening to see the power of testing and the clarity it provides first hand.  As I become more familiar with my surroundings I look forward to writing tests first to avoid the confusing messes altogether.