Maarten Balliauw {blog}

ASP.NET MVC, Microsoft Azure, PHP, web development ...

NAVIGATION - SEARCH

ASP.NET MVC TDD using Visual Studio 2010

Phil Haack announced yesterday that the tooling support for ASP.NET MVC is available for Visual Studio 2010. Troy Goode already blogged about the designer snippets (which are really really cool, just like other parts of the roadmap for ASP.NET MVC 2.0). I’ll give the new TDD workflow introduced in VS2010 a take.

kick it on DotNetKicks.com

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:

Step 1

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.

Step 2Go ahead and start typing the following test:

Step 3Now when you type CTRL-. (or right click the DemoController unknown class), you can pick “Generate other…”:

Step 4A new window will appear,  where you can select the project where you want the new DemoController class to be created. Make sure to enter the MvcApplication project here (and not your test project).

Step 5

Great, that class has been generated. But how about the constructor accepting List<string>? Press CTRL-. and proceed with the suggested action.

Step 6

Continue typing your test and let VS2010 also implement the Index() action method.

Step 7You can now finish the test code:

Step 8The 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:Step 9Run your tests and see it fail. That’s the TDD approach: first make it fail, and then implement what’s needed:

Step 10

If you run your tests  now, you’ll see the test pass.

Conclusion

I like this new TDD approach and ASP.NET MVC! It’s not ReSharper yet, but I think its a fine step that the Visual Studio team has taken.

kick it on DotNetKicks.com

blog comments powered by Disqus