Tuesday, September 29, 2009

Book Review: Art of Unit Testing

image Somehow this year has been one where I spend a lot time reading. Last week I finished Roy Osherove's The Art of Unit Testing, and I've almost finished reading Kent Beck's TDD by Example. After that, I'll jump right into Robert (Uncle Bob) Martin's Clean Code; A Handbook of Agile Software Craftsmanship.

I met Roy about two years ago when I, Don Smith and Olaf Conijn attended a late-night dinner during the 2007 TechED Europe in Barcelona. The funny thing is that I don't even remember what his sessions were about, but I won't forget the fact that he finished them with some hilarious guitar playing. I do remember though some guys from the company behind TypeMock stalking him. And apparently that worked; he is now one of the company's most visible employees. Since then he has blogged a lot of about Test Driven Development and Unit Testing, so I was really eager to read his recent book, The Art of Unit Testing.

Let me start by making it very clear that this book is not about Test Driven Development. One of my colleagues recommended it when somebody else asked about a good book about TDD. If you're looking for that, refer to Kent Beck's TDD by Example, Jimmy Nilsson's Applying Domain Driven Design or the many blog posts written by Jeremy D. Miller. At least, those are the ones that helped me get started.

The book does a great job in explaining the advantages of mocking frameworks in comparison to hand-written stubs and fakes. And since Roy is working for TypeMock these days, I was really expecting him to plug their product TypeMock Isolater throughout the entire book. But I'm not sure whether he was already working for that company at the time he had written the book, I never found him suggesting one product was better than the other.

One thing I didn't like were some his examples in chapter 6. From my point of view, he was demonstrating how to end up with obscure tests. Especially his suggestion to refactor all kinds of shared logic to a general setup method or a test base-class causes the stuff you need to know to understand a test to end up on lots of different places. xUnit Patterns has some much better solutions for solving such problems. And as in many test-related books and articles, it seems that almost nobody is mentioning the patterns of all patterns, the Test Data Builder. That one has proved to really help keep my unit tests readable.

Also, if Roy is ever going to publish another edition, it would be nice to add an intro on Behavior Driven Development (BDD) as well. BDD really helps to ease the thinking process of writing proper specifications.

All in all, I think this book deserves a score of 3.5 (on a scale from 1 to 5). In essence it is a great introduction to everything you need to know to get started with unit testing. Especially chapters 7 and later provide very useful guidance on how to get started and how to deal with the more difficult challenges, both technical as organizational. He shares a lot of his own experiences, and I particularly liked the ones where he failed because he's not afraid to share the lessons he learned himself. Granted, Gerard Meszaros' xUnit Patterns contains a lot more in-depth coverage of proper test automation, but Roy's book manages to cover all aspects in a very readable form.

Tuesday, September 01, 2009

A day and night at the NRW09 Conference in Germany

About 1,5 year ago I first met Daniel Fisher when he and two colleagues from NewTelligence, a German consultancy firm, hosted a full-day session on advanced .NET 3.0. During the breaks, we ended up talking about software factories and stayed in contact through MSN and email.

Since then, he started DevCoach, his own company, and became very active in the German .NET community through the Just Community initiative. In 2008, he and Stephan Oetzel organized their first full-day event, the NRW Conference, roughly comparable to our SDN events. Last year he invited me to do a talk in Wuppertal, but due to holiday conflicts I had to drop the opportunity. But this year, I did make it, and it was fun.

The event started on Thursday evening with a speakers dinner in Pöschkes, a local restaurant. Since I wanted to avoid the traffic, I left Rijswijk at around 14:00 and arrived at Wuppertal at around 17:00. I forgot how fun it was to drive the German autobahn where most of it still does not have any speed limit. Diner started not until 20:30, so that gave me some time to take a walk in the vicinity of the Ibis hotel, which by the way, was a simple but descent hotel. Unfortunately, it had no Wi-Fi and my phone's GPRS connection did not work either. I then went to the event location to meet the rest of the speakers, which appeared to be a rather unusual place. Instead of the typical conference center this event was held in a kind of cultural center/club named "Die Börse". Definitely an interesting place to hold an event for developers.

Dinner was excellent, but lasted a bit long and other than Daniel and Stephan it appeared to me that most Germans are a bit too reluctant to speaking English. Fortunately, I was sitting next to Sergey, who accompanied Daniel in the Netherlands, Lars Corneliussen, a very funny but loud German speaker, and Phil Winstanley, the only other non-German speaker. Although very young, he appeared to be a seasoned speaker and has been MVP for many years. The three of us enjoyed some interesting discussions throughout the entire evening and finished the night at around 01:00 with a final drink at the hotel's bar.

The next morning at 8:00 we all met at the venue to receive some drinking coupons and our speakers shirt. The first session started at 9:00 with a rather spectacular recap of last years edition and some encouraging words from the organization. Luckily I do understand German (although I don't speak it that well).

My session started at 11:10 and appeared to last only one hour instead of the usual 75 minutes. The session was held in the main room where the keynote was held, so it looked rather empty, even though there were about 35 people in it (of the 102 attendees in all four tracks). The talk ran fast and reasonable smooth, but at the end, nobody asked questions. However, I got a score of 1.7 on a scale between 1 (excellent) and 6 (aweful) so it is probably the language. Most Germans are not accustomed to speaking English even though I did not expect that from a developer community. Phil, who gave an excellent interactive talk on ASP.NET MVC versus WebFoms did not get any questions either.

I also attended Sergey's session on Orthogonal Architecture where he explained how you could apply the S.O.L.I.D. principles on an architectural level. I found that idea very interesting, so I just might ask Sergey whether I could use his slides to do this talk in the Netherlands. Since I had plenty of time to spare I also went to a talk on JQuery delivered by a German speaker I forgot his name off. I have not used JQuery yet, but I see why Microsoft decided to include it in the next version of ASP.NET. At around 18:30, after attending Phil's session and having dropped him off at the Dusseldorf airport, I finally drove back home.

You can view (or download) the slides below and download the source code of my demos from here.