Showing that fear of mediocrity can make the world a better place.

Which is more valuable – the test or the TDD process?

Roy gives an up-to-date and thorough flogging of MSTest here I have to say that while I agree with his notes about the failing of the framework I also dislike the initial developer story for MSTest and the tooling it provides.

I was recently introducing a co-worker to unit testing and test driven development. The co-worker created the unit test template project as per the Visual studio template. Then he proceeded to write some code and use the magical “Generate test for method” functionality in Visual Studio. After his code had some weight to it he asked for input on his tests. He mentioned that he was having a hard time testing one thing in isolation. The test were brittle and had to be changed every time he made a code change. He was practically wiring up the entire system to test a singe method. I wasn’t sure how he got the code to this point. Isn’t TDD supposed to help you write more maintainable code and tests by design? After he showed me the workflow he was using – write “production” code, generate test, wire up the rest of the system to run the test, run test I realized where he was misled.

The magic of test driven design is that the test drives the design. Shocking I know. In order for that to happen the test has to be written first. That simple action has an amazing effect on focusing the code and the scope of what needs to be written to make the test pass. The fact that Microsoft was “kind” enough to let you generate those stupid tests that everyone is talking about shows that Microsoft doesn’t get TDD. Just having tests for the code is useless. I can show you a project with thousands of lines of code in unit tests that do nothing but add bulk to an overweight application. They are worthless unless they positively influence the design of the system.

I say that the process of test driven design is much more important that the particular framework. I don’t use and don’t recommend MSTest because it teaches you the wrong thing out of the gate. You are led down a path that makes you hate testing and provides no real value. Stick with any other framework except for MSTest and you have less chance of things going wrong.

Fortunately this story has a happy ending. The co-worker was more than happy to give my recommendation a shot and he is now happily building a more maintainable system and tests using NUnit and writing the tests first. You are welcome future application maintainer 😉


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s