Creating a new controller, the TDD way
First of all, I’ll create a new ASP.NET MVC application in VS2010. After installing the project template (and the designer snippets if you are cool), this is easy in VS2010:
Proceed and make sure to create a unit test project as well.
Next, in your unit test project, add a new unit test class and name it DemoControllerTests.cs.
Great, that class has been generated. But how about the constructor accepting List<string>? Press CTRL-. and proceed with the suggested action.
Continue typing your test and let VS2010 also implement the Index() action method.
The cool thing is: we did not have to go out of our DemoControllerTests.cs editor while writing this test class, while VS2010 took care of stubbing my DemoController in the background:Run your tests and see it fail. That’s the TDD approach: first make it fail, and then implement what’s needed:
If you run your tests now, you’ll see the test pass.