For TDD in VSTS: Ctrl+K, M To The Rescue (Generate Method Stub)

Much has been made about Microsoft's poor attempts to “get“ TDD with VSTS. One of their obvious mistakes is the “Create Unit Tests“ feature. You use this feature to generate your units tests from your implementation code, which any semi-versed TDD practitioner will tell you goes against what TDD is all about: writing your tests first and then writing your implemtation logic.

However, what I'm finding interesting is the lack of play that the “Generate Method Stub“ feature is getting. This feature does what TDD practitioners want: it generates your implementation signature in the designated class, complete with appropriately typed parameters and a “throw new Exception()“ statement, thus enforcing good TDD practices. From there you can refactor as necessary, thus living the mantra “Red-Green-Refactor“. But again, I find it very perculiar that the people who (rightfully) slam Microsoft for things like “Create Unit Tests“ don't bother mentioning “Generate Method Stub“. Or maybe they just don't know it's there.

Keep in mind that “Generate Method Stub“ can only be used on methods; it cannot be used to generate classes. If you try to generate a class from a unit test using “Generate Method Stub“, you get this hilarious error: “Could not determine the type on the left side of the dot“.

So, how do you invoke “Generate Method Stub“? The first thing to do is place your cursor on the method in the test. Then you've got a couple different options. My favorite is simply to hit Ctrl+K, M. You could also right-click on the method and select it (which I've noticed it doesn't always show up in the context menu 100% of the time). Or you could go to Edit > Intellisense > Generate Method Stub.

And there you have it. Stick that in your pipe and smoke it :-)

And BTW, it feels good to blog again.

Print | posted on Tuesday, January 17, 2006 9:01 PM

Feedback

# Possibly the best error message ever

left by Digging My Blog - Dan Hounshell at 1/18/2006 6:55 AM
"Could not determine the type on the left side of the dot"
Dave Donaldson inadvertently demonstrated...

# re: For TDD in VSTS: Ctrl+K, M To The Rescue (Generate Method Stub)

left by Dan Hounshell at 1/18/2006 6:56 AM
Dave, please post a screen shot of this fantastic artifact.

# Generate Method Stub

left by .Avery Blog at 2/3/2006 6:17 PM
Comments have been closed on this topic.