Niclas Nilsson home

Microsoft and Test-Driven Development

Two times, I’ve seen Microsoft Sweden demonstrate Visual Studio 2005. Two times they showed a distorted view of Test-Driven Development (TDD) and unit testing. Each time a different presenter.

First, let me clarify that I think it is really good that Microsoft has integrated unit testing tools into Visual Studio. These kinds of tools existed before on the Microsoft platform, most notably open source tools like NUnit, but for some reason, some Visual Studio users do not adopt things that has not been branded by Microsoft. With Visual Studio 2005, more developers get the opportunity to write tests - hopefully before they write the production code.

At both demonstrations, they showed the integrated testing utilities and completely missed the point. They first explained that TDD was about some extreme people who write their tests before the real code, but that it was a bit to extreme for them. Then they showed how Visual Studio can generate tests from the production code. Fair enough. Of course, it is only unit testing and not TDD, but that works for some people. It is certainly better than not having tests, but it does not drive your design the way TDD does. A pity, but better than nothing.

After they had generated a test from the production code, they ran the test. As expected, it failed since the generated test method only had a few default asserts that are meant to be replaced. A good start. But then it happened. Both times. They showed the audience how to remove all the asserts (bad, very bad), add some print statements instead and explained to the audience how they should check the results in the console output to make sure it was the expected output.

I was stunned. When I think of it, I still am. I really hope no single developer in the audience bought it, but if this was their first encounter with a testing framework, my guess is that they managed to do some harm, especially since the demonstration came from the vendor of their main tool. The ones that bought it will not have any of the benefits that comes with red-green-refactor and not even the benefits from having automated tests.

I doubt that this is Microsofts normal view of unit testing and TDD since their Patterns & Practices department communicates the commonly accepted TDD approach, since they employed the NUnit guy and since they even managed to get Ward Cunningham on their payroll for a while, so my hope is that this is only some kind of internal educational glitch between the developers and the presenters. But still - this was what the audience got. And I worry they’ve showed the same thing to a few thousand Swedish developers.

A lot of damage done.

If anybody reading this got tricked by their presentation and want to know what TDD and unit testing is really about, send me and email (in English or in Swedish) and I’ll explain what you missed out on.