Rants, rambles, news and notes from another geek

Unit Testing Rules

I was just sent this post by Michael Feathers where he asserts:

A test is not a unit test if:

  • It talks to the database
  • It communicates across the network
  • It touches the file system
  • It can’t run at the same time as any of your other unit tests
  • You have to do special things to your environment (such as editing config files) to run it.

Tests that do these things aren’t bad. Often they are worth writing, and they can be written in a unit test harness. However, it is important to be able to separate them from true unit tests so that we can keep a set of tests that we can run fast whenever we make our changes.

This is a very interesting set of rules and for the most part I agree with Michael. When I do TDD I try to avoid these things as much as possible. But when I find myself needing to break one of these “rules”, I almost always end up doing the same thing.

I create a single minded little class that does that one thing. Then I test it to ensure that it does it. Then I walk away from it.

As an example, consider a business class that needs to pull some information from an XML file on the file system. That is what the customer requirement was. However, I would never even consider putting XML or file system logic in that business component. Instead I’ll write a class that talks to the file system and returns some sort of domain model (not XML). I’m now free to test my business component using a mock of this persistence loader, completely in isolation of the file system.

I think Michael does the same thing. He continues:

That might sound a little severe, but it is medicine for a common problem. Generally, unit tests are supposed to be small, they test a method or the interaction of a couple of methods. When you pull the database, sockets, or file system access into your unit tests, they aren’t really about those methods any more; they are about the integration of your code with that other software. If you write code in a way which separates your logic from OS and vendor services, you not only get faster unit tests, you get a ‘binary chop’ that allows you to discover whether the problem is in your logic or in the things are you interfacing with. If all the unit tests pass but the other tests (the ones not using mocks) don’t, you are far closer to isolating the problem.

Frankly, we need both kinds of tests, but these “pure” unit tests are undervalued.

I guess the only part I don’t really like is that distinction between other tests and pure unit tests (emphasis mine). I don’t think it is safe to ignore these other _**tests and I don’t know what to call them other than **_unit tests, so I’m hesitant to accept the part of Michael’s post where he says, “A test is not a unit test if…”

I would much rather say this: “A unit test should try to avoid…” and then follow it with his five bullets.

i-Mate for Sale?

If anyone got one of the i-mate phones this morning and doesn’t want it, please let me know. I’ll buy it from you.

Patterns & Practices Pre-Conference Session (Pt 2)

When we left off, Ron had finished his Phil Donahue bit and we were heading into the real talks. Ron went first by himself and introduced all of the concepts and terminology around Service Orientation. After Ron, Arvidra and Beat presented some of their learnings around SO from MS EMEA (Europe, Middle East and Africa). They’ve done some really cool work and it was cool to see it.

During all of that I was tweaking the code for my demo. I don’t know about you, but I just can’t leave well enough alone.

After Beat and Vin&nbsp_place_holder;finished, we broke for lunch. We had run a little long, so we only gave them 55 minutes to grab food and get back. No worries, though, that should be plenty of time.

And then… with 10 minutes to go in the break, there is a loud POP.

And the lights went out.

There were some emergency lights on, so the room was dimly lit. But everything else was down.

The tech guy came over and said, “Hey… umm… we were kinda expecting that. The other half of the building has been down for 10 minutes already.”

“Oh shit,” I said.

“We don’t know when it will be back up. Sorry. I’ll let you know when I have more information.”

Ron still wasn’t back from lunch, so Don Smith and I stood up on the stage and yelled, “Hey everyone. I need your attention. As you can see the power is out and apparently is is the whole local neighborhood. Ummm. We’ll give you more information soon.”

Most people laughed a bit. From the stage it was kinda cool looking. About 50% of the people had their laptops open (even though the wireless was down) with the glow of the screen on their face. Cool looking.

Ten minutes later, Ron showed up to continue the talk and realized the pickle we were in. After a brief chat we decided to do an impromptu panel discussion. People yelled out questions about SOA, XSD, Contract-first development, etc. and we all stood up on stage, in the dark, and tried to answer them.

It was weird, but strangely, it was fun.

After about an hour, the power came back on and we got back to work.

Next up was Don Smith and Beat Schwegler who talked about some really cool automation that they’re doing to enable Contract First service development in VS using GAT. Very very cool. I don’t think we (p&p) are shipping it yet, but people liked it. (If you think we should ship it, drop an email to Don at&nbsp_place_holder;don dot smith at microsoft dot com and let him know.)

After Don and Beat finished, Ron Jacobs and I got up and talked about CAB.

“What is the Smart Client guy doing at an SOA talk?” I hear you asking.

Well, consider this: In an enterprise one of the best ways to enable the consumption of lots of different services is to provide ready-to-go UI modules that people can plug into their apps with ease. And that’s what CAB is all about. So why not?

I showed the newest bits of CAB and people who had already been playing with CAB were excited to see some of the changes we’ve been working on. After we finished about a dozen people came up to ask questions and chat. It was great. I was glad to have the opportunity to talk to people about it and to get their reaction to what we’re doing. Very cool.

We finished with some excellent material from one of our customers (sorry–I forgot his name) who has actually implemented SOA and ESB within their org. The whole experience was great and I’m really looking forward to the rest of the week.

Assuming the power stays on.

Patterns & Practices Pre-Conference Session (Pt 1)

PDC is here. I’m sure you know that already, but it is really here. And I am here too.

I flew in yesterday afternoon, arrived just in time to grab dinner with Vin, Beat, Ron, Don, DonXML, and Edgardo. We had Tapas at the restarant across the street from the Westin Bonaventure. It was great.

After dinner everyone went back to their rooms but I decided to take a lap around the lobby bar to see who was there. I found Scoble, Jeff Key and a bunch of other very cool people from all over the world. Since I’m presenting as part of today’s pre-con session, I probably should have gone to bed, but I didn’t. Instead I spent time with customers and colleagues drinking Guiness.

Mmmmm…. as they say in the old county: Guiness is Good For You. (Maybe I should do the Guiness diet this week? I think not.)

This morning I was actually feeling fine, which is one of the reasons I drink the black stuff (no hangovers). I hooked up with Vin and Beat in the breakfast cafe and we headed over to the conference center for our pre-con session with Ron Jacobs.

Which is where I am now. Sitting off to the right, watching Ron tell his stories. If you’ve seen Ron Jacobs talk before, then you know what I’m talking about. Ron has this amazing gift-of-the-gab kinda thing that leaves me in awe. I think I’m a pretty good speaker, but Ron really is amazing. He can tell a story about getting stopped at a border crossing into Canada and turn it into a discussion about Service Orientation Tenet #1. Amazing.

But I have to rewind a bit. Because one of the funniest things happened in the 15 minutes leading up to the start of the session.

First of all, Ron is dressed in a suit. Not the traditional (required) blue Microsoft speakers shirt. A suit.

Ron: “I was there when Don Box gave his presentation in the nude and I decided that I needed to do something to make me stand out. No other speakers will be wearing a suit, right?”

But that still isn’t the funniest part.

Ron: “I got this suit the last time I was in Bankok. Isn’t it nice?”

Some people wouldn’t brag about their Bangkok suit. But Ron does. But this still isn’t the funny part.

Let me set this up with a bit of role-playing. You are attending the pre-con, wandering around the conference center looking for the patterns & practices pre-con session. The conference center is huge and you’re dazzled by the signs and monitors and videos and food and drinks and famous people and all that.

Then you round the corner and see a sign that tells you you’ve arrived at your destination. You open the door and walk into…

The Phil Donahue Show Hosted By Ron Jacobs

There is Ron, in his suit, walking up to you with an outstretched microphone…

“What’s your name?”

“Did you have a good weekend?”

“Where are you from?”

“What is that cool little gadget in your pocket?”

“What would you like to learn today?”

“Do you like my new suit? I got it in Bangkok…”

To be continued…

Almost PDC Time... Some Information About My Schedule

I think I got most of my “work stuff” taken care of yesterday. Brad and I are doing some really cool re-engineering of parts of the core in CAB and I think we got the most important bits done before I left. I’ve really enjoyed working with Brad these past few months, he’s an excellent developer, a fun TDD pairing partner and an all around good guy. I know the code is in good hands. But I digress…

This morning (Sat) I got up and except for Hadley (the three year old), everyone is sick, including myself. Ugh. What a great way to head off to eight days at a conference.

Oh yeah, PDC… that’s what this post is about.

I would love to hook up with any readers who are attending PDC this year. I met a lot of new friends at the last PDC and would love to meet up with more friends this time around. As long as I’m not on stage or working, I’ll probably be online (battery life permitting). You also can email me at peter dot provost at microsoft dot com.

P1010026 (100x120)And as I did two years ago, here is a picture of me. If you see me in the halls, grab me and say hi. I have to ask one favor though… I’m kinda famous for forgetting people’s names, so if the name on your badge isn’t facing out, please bear with me and my forgetfulness. It isn’t personal, I just have a broken index.

I also want to share my “work” schedule at PDC05 with all of your in case anyone who is attending wants to find me the old fashioned way. If you know of any parties or get-togethers that fit in my schedule, drop me a line and let me know!

Sunday Sept 11

  • 6:00pm - I arrive in LA at about from Seattle and will be staying at the Westin Bonaventure.

Monday Sept 12

  • All Day - I’m doing a session on CAB as part of PRE13 - Patterns and Practices for Designing Service Oriented Applications – An Illustrated Example in Room 502AB with Ron Jacobs. I don’t think I’ll be on stage the entire time, but I will be around there somewhere.
  • Evening - I’ll be away from the conference at a private party. Sorry.

Tuesday Sept 13

  • 2:30pm - 5:30pm - I’ll be working in the Tools and Languages Track Lounge
  • 5:30pm - 9:00pm - I’ll be working in the Microsoft patterns & practices Product Pavilion booth during the big Expo Hall reception. Last year there was free beer and food, so don’t miss it.
  • 6:30pm - 9:30pm - I can’t decide if I’ll try to get over to either the Mono get-together or the PDC Underground Party. Maybe both… maybe neither. We’ll see.

Wednesday Sept 14

  • 12:30pm - 3:30pm - I’ll be working in the Microsoft patterns & practices Product Pavilion booth
  • 7:00pm - 11:30pm - The attendee party at Universal Studios Hollywood. This year I’ll be meeting up with some friends at the beer garden near #17 on this map, and if it is anything like last year, I’ll be staying there chatting and drinking for most of the night.

Thursday Sept 15

  • 12:00pm - 3:00pm - I’ll be working in the Microsoft patterns & practices Product Pavilion booth
  • 6:30pm - 9:00pm - I may be participating in the Ask The Experts sessions. Not sure yet.

Friday Sept 16

  • 10:30 - 12:00 - I’m participating in PNL01 Advances in Agile Development in Room 409AB. If you’re still around on Friday, please come to this session. We’ve got a lot of interesting people on the panel, not just MS folks. We’ve got some CMM folks, some external agile people, some MS folks, etc. Hopefully it will be a lively discussion. Come armed with your questions!

Saturday Sept 17

  • I fly home to Seattle at about 10:30am on Saturday. I may try to get out Friday night instead, but I’m not sure yet. If anyone wants to do something Friday night, let me know before then or I may not be around.

Have a great PDC everyone!

PS. Billg’s keynote is going to be broadcast live, so those of you who aren’t attending can stay involved. More information about it http://msdn.microsoft.com/events/pdc/ and you can watch Bill’s speech at http://www.microsoft.com/events/executives/billgates.mspx.

Enterprise Library BOF at PDC

From TSHAK:

The EntLib PDC BOF you voted for has been accepted! It will be held on Monday, September 12, 2005 at 8:15 PM. When you register at PDC you should have a map that will indicate where the BOF sessions will be held. I hope to see you all there!

I’ll be there!

Recommended Book List Updates

I just did a bit of catch up on my recommended book list (in the left side bar of the blog for those of you who only read me via RSS). Here’s what I added:

  • Working Effectively With Legacy Code by Michael Feathers - When talking about TDD and unit testing around MS, this is almost always one of the first books I recommend. To Michael, legacy code is code that doesn’t have effective unit tests.
  • Customizing the Microsoft .NET Framework Common Language Runtime by Steve Pratschner - This is one of those books that is an interesting read, because you don’t really need the information provided but it is really cool to know how to do it. Then months or years later, when you really do need to know how to host the CLR in your own process (for example), you at least know how to get started.
  • Extreme Programming Pocket Guide by Chromatic - If anyone ever asks you to recommend one and only one book to explain XP, consider this one. I remember when I first saw it on Ward Cunningham’s desk. I asked if it was okay and he said, “He got it all… in one little book. That’s why I wrote the forward.”
  • Pragmatic Version Control Using Subversion by Mike Mason - Another book in the Pragmatic series, this time about my favorite open-source version control system: Subversion.

PDC Panel - PNL01 Advances in Agile Development

For those of you who are going to PDC and staying until the end, please come by the Advances in Agile Development panel on Friday. I was just invited to sit on this panel and I’m really excited.

PNL01 - Advances in Agile Development

September 16, 10:30 AM - 12:00 PM 409 AB Clemens Szyperski, David Anderson, Don Reinertsen, Donald Reifer, Jim Newkirk, Kumar Vadaparty, Peter Provost, Randy Miller

The pressure for application development teams to deliver more value to the business has never been greater. No single methodology fits all project types, yet it’s critical to provide a common framework and taxonomy across projects and teams. Come see how industry gurus and leading services organizations discuss advances in using a combination of agile frameworks and methodologies, like ‘MSF for Agile Software Development’ to deliver real business value by helping development teams meet aggressive delivery schedules and achieve better, faster, and cheaper results, while at the same time adapting to changing business requirements.

Agile Software Development Survey

The patterns & practices Product Manager, Eugenio Pace, has just posted a survey asking you, our customers, how you are using agile practices out in the world, and how we can help. From Eugenio’s blog post announcing the survey:

Lately, there has been an increasing interest in applying agile methods for software development. Practices like test driven development (TDD), continuous integration (CI), highly iterative development cycles, daily team meetings, use of wikis, and others are some of the techniques that support what has been called an agile process.

My team (patterns & practices) has been using all these techniques for its internal software production process with high success. Enterprise Library are CAB are two examples of such projects.

We are lucky to have expert members in our team around this subject. Guys like Ward Cunningham, Peter Provost, Brad Wilson, Scott Densmore, Brian Button, Edward Jezierski have been strong advocates of this type of software development process.

Everyone that gets to know how we do things, (like the war room) becomes very interested about it and usually wants to learn more. They hear about lower bug rates, increased quality, better traceability between requirements and implementation, fast turnaround of new requirements, etc.

So, how about packaging all these in a guidance offering? Take all our experience and lessons learned in applying such techniques in our environment and frame them in a way it could be used by our customers and partners on thier own projects.

Our team has interesting characteristics in terms of the deliverables it generates (books, code, tool based guidance), so it means puting together teams with very different skillsets, not just software developers (technical writers, developers, testers, marketing guys, etc) also across wide spread geographies.

What do you think? Would this be something valuable? If you think so, help us understand how, why and what would be valuable for us to do.

If you are interested in helping us out, please take a few minutes and take the survey. Even if you don’t use agile, please take the survey because that will help us better understand your needs.

Click here to open the survey in a new window.

Thanks!

The Pair Programming TDD Game

Lately, Brad Wilson and&nbsp_place_holder;I have been playing an interesting game while pair programming. Brian Button and Ward Cunningham (who has moved into the war-room) were sitting watching us play it the other day, and they said, “Have you ever blogged that?”

“Nope,” I said. “Why? Haven’t you seen people play the TDD game before?”

Well, they hadn’t, so I decided to write a little bit about it.

Here are the rules:

  • One person writes a test. If it passes, he must pass the keyboard to the other person who gets to write a test.
  • If it fails, he passes the keyboard to the other person and they have to implement the required code to make it pass.
  • If “the light is green,” the person who has the keyboard can choose to perform a refactoring instead of writing a test. In fact, if the implementation given by the other person has some duplication that needs to be removed, they are obligated to do just that. (After which, of course, the other person gets to write a test.)

I’m sure all of you who are reading this (especially the non-techies) are now saying, “Oh my goodness. That sounds like the most fun game in the world! I can’t wait to go home and play it with my grandma Josie!” (Sorry… I started channeling Rory there for a minute.)

Seriously though, there are some interesting positive things that come from playing the game.

First of all, it encourages each partner to focus on small elements of functionality. Pairing does this too, but playing the game makes it even more real because what seems to happen is that each person tries to do something that doesn’t take them long, and makes the other person take longer.

Yeah, that sounds selfish and mean, but we are human after all.

What is really cool about this is that when the code is really well factored, as it should be if you are playing the game, then the pattern tends to end up something like this:

  • Peter writes test in 2 minutes
  • Brad writes implementation in 1 minute
  • Peter writes test in 4 minutes
  • Brad writes implementation in 1 minute
  • Repeat 4 or 5 more times
  • Peter does a refactoring to clean up the mess that Brad created.
  • Brad writes a test in 2 minutes…

Red-Green-Refactor

As you can see, this is exactly the “Red-Green-Refactor” pattern called for by XP and TDD, but it adds the interesting twist of making it slightly competitive. But not so competitive that the code suffers, just competitive enough to keep it interesting.

So now I’ve blogged it and maybe you’ve had some fun reading about it. And hopefully you’ll give it a try the next time you’re pair programming. It is a blast.