Sunday, February 24, 2008

TDD Gone Wrong

Last time I wrote about TDD. I read this article from some guy at Spring about doing TDD with the Google Web Toolkit. I have to say this is a good example of how TDD zeal can lead to some twisted thinking.

The article starts by point out how GWT enables RIA development in pure Java. That's a good thing. He then talks about some of the difficulties he's experienced trying to write unit tests for GWT widgets and concludes:

views are usually very hard to test, therefore they should know and do as little as possible ... Most of the GWT code has pretty much all the logic in widgets, so most developers using GWT extend a widget and just add some more logic. My advice is simple: don't go there.

RIAs are all about putting lots of logic in your view. Now it's not just any logic, but view logic. You see there is logic involved in creating a rich user interface and the place for that logic is the user interface. So this guy's obsession with testing has led him to the conclusion that you should dumb down your view code so you can test it. This completely defeats the purpose of using GWT. Very sad.

I think the author does bring up some valid points on unit testing GWT. If you place a huge importance on unit test coverage, then the more logical conclusion is that you should not use GWT. Don't try to dumb down the technology so that you can sleep better at night. Just pick a different technology.

3 comments:

Rob van Maris said...

I find it hard to understand what point you're trying to make here. This "guy at Spring" is not arguing that you "should dumb down your view code", but rather in favor of moving the logic that you would like to test to a Controller component, where it can be tested without a need to instantiate GWT widgets.

Perhaps you're confusing view code with UI code, instead of View code as in Model -View-Controller.

In case you have any doubts, you might want to read the blog post I wrote about the same subject.

Michael said...

You are right Rob, I misunderstood the original post. I thought the controller code was server code, not client code. I took a look again and realized my mistake.

So if you moved logic from client to server just so you can test it more easily, I would still argue that is a big mistake. However, the "guy at Spring" a.k.a. Iwein Fuld did not make that mistake.

Your blog also does a good job of explaining the concept. Thanks for correcting me.

Rob van Maris said...

So that's settled then. I'm glad I asked ;-).