Crafting Java with Test-Driven Development, Part 12: TDD at Cassatt: An Interview with Jerry R. Jackson
I met Jerry Jackson while working at a now-defunct dotcom called ChannelPoint; I was there from 1998 through 2000. ChannelPoint, which had been founded by a number of former Sun developers (including Jerry), had a higher-than-average population of Java authors. I believe there were five, including Jerry and me.
I hadn’t seen Jerry until about three years ago, when I ran across him at a chess tournament. Both our sons were competing. Chess tournaments are a long day for non-competitors—you’re usually unable to watch the games, and there are long waits between games. (Figure on spending a full Saturday for the ordeal to play out.) So I had an opportunity to catch up with Jerry. We talked about test-driven development (TDD), which Jerry had read about but hadn’t yet tried. I talked about some of the successes I had seen from it, and about what it had done to improve my notions of design.
Fade to 3–4 months later and another chess tournament. As I approached Jerry, the first words out of his mouth were, "This TDD stuff is so cool!" This is a typical reaction; after trying TDD honestly for at least a month, virtually everyone I’ve met comes back to me glowing. A frequent comment is that they’ll never go back to the old way of doing things.
Since that second chess tournament, Jerry has moved on to Cassatt, a software company headquartered in San Jose. He works in Cassatt’s Colorado Springs development team. Cassatt’s main product is Cassatt Collage, which creates an automated, on-demand computing infrastructure from a customer’s existing servers, networks, and storage.
Jerry took with him to Cassatt what he learned about TDD. Today they’re still practicing it with great success. The Cassatt team is currently working on release 3.4 of Collage.
Jeff: How many developers are doing TDD at Cassatt, and how long have you all been doing TDD?
Jerry: There are approximately thirty developers at three sites, depending on how you classify people. Most are now doing TDD. Probably the main exceptions would be the functional and system test developers. TDD for them would threaten an infinite regress.
A subset of the team who worked together before coming to Cassatt started doing TDD at a previous company. We’ve been doing TDD for more than three years (ever since the chess tournament). We switched our development style practically overnight. That’s not to say that we had it all figured out right away, but that we could tell there was no going back.
Jeff: What do you mean by "infinite regress"?
Jerry: I just meant that they’re developing tests as their product, so one could argue that they should develop them test-first, but then, shouldn’t those tests be developed test-first as well?
It just seems strange to develop test code test-first.
Jeff: How did you get the developers to agree do TDD?
Jerry: I was ready to lobby hard for it early on, but there turned out to be almost no resistance from the team at the local site. Some of the others had heard about it as well and were already interested. It was a much harder sell for the people at other sites. We were the newcomers at that company and habits were pretty entrenched. Our remote connection to a lot of the other developers was too low-bandwidth to give us much leverage. We weren’t really very successful in convincing many of the existing developers.
Jeff: How did they learn?
Jerry: Learning about TDD didn’t turn out to be a big problem. After I circulated a pointer to an online article about TDD, everybody got the basic idea. After that, we read some more but mostly learned by doing. There are things that are difficult to approach with TDD, but even trying to do so is very educational.
Jeff: How did you keep the team on track with TDD?
Jerry: We decided from the beginning at Cassatt that no code could be checked in without tests, and took some pride in watching the test suite grow. In addition, there was a significant cultural "attitude" that formed. Code that had no (or few) unit tests came to be widely considered unreliable and suspect (as it is). Eventually, the idea of writing code without driving it via tests became very disturbing to most of us.
Jeff: Tell me a bit more about the resistance you’ve encountered.
Jerry: I’ve seen four main kinds of resistance:
- The first is basically inertia. Most people don’t like change. They’ve developed in the same basic way for a decade; why should they change now? This can eventually be overcome simply by demonstrating the benefits. Even with inertia, if the benefits are significant, most people can motivate themselves to change.
- The second area of resistance I’ve seen is pride. "Who is he
to tell me how to write software? I know how to write software. I’m really
good at it." Some people are simply unwilling to entertain the idea that
they could have been doing their jobs a lot better throughout their careers.
This seems to be more common among more senior engineers—who, after all,
are already supposed to know a lot about developing software.
The way to address this resistance is to play to someone’s ego rather than against it. "It’s no doubt obvious to a person of your ability and experience that this development model can produce significant benefits...." Once you point that out, a really good developer is usually quick to see the light, and you can get a pretty fast about-face.
- The third barrier is a deep-seated dislike for writing tests. Most
developers think of writing tests for their code as an unpleasant chore they
have to do after the fun part of the job is over. I think there are two reasons
for this. First, writing code is like any kind of writing. There is a tendency
to develop a bit of writer’s block after completing a major work.
It’s right then that one is expected to go back and write tests. Nobody
wants to do that. They’re done with that code—it’s time to
move on. Also, when one is confronted with a huge piece of completed code, the
task of writing unit tests for all of it is daunting and there is never enough
time to do it right. Once you’ve declared code finished, the company wants
you to write other code (and rightly so—you said it was finished). This is
a formidable barrier.
It’s hard to convince someone of how different it is to write unit tests as part of development rather than after the fact. I really don’t know a good approach to this one other than to hope that time and discussions with other developers will eventually wear down the resistance.
- The fourth and last kind of pushback I’ve run into is actually somewhat valid. Some kinds of development are difficult to do using TDD.
Jeff: At Cassatt, what are some of these difficult things?
Jerry: The main areas that are hard are the parts of the application that run on top of the asynchronous infrastructure. We have significant application logic that has to run in an environment where asynchronous inputs can come in from monitoring, the user, timers, etc., and any ongoing activity has to adapt. The state of the system that’s tracked by the logic is very complicated and it’s hard to simulate. So our tests require a lot of support and take quite a while to run. This makes it a lot more painful to use TDD (though we still do).
I’ve heard people say that GUIs are hard to write test-first. We’ve only done web UIs so far, and they seem pretty amenable to TDD.
Jeff: How would you describe your source base?
Jerry: There are significant areas of our source base in which developers feel very comfortable making large-scale changes. It’s extremely liberating to be able to make a change and know immediately whether it’s correct or not.
In addition, people find it easier to work in unfamiliar areas since the test failures that occur when they make changes guide them to an understanding of the code. ("Ah, I changed x and that caused y to fail...I see the connection.")
Finally, even in areas where it’s difficult to do everything using TDD, the attempt to do so usually leads to less coupling and better-organized code in general.
Jeff: What are some of the things you have to watch out for with respect to doing TDD?
Jerry: One of the things I run into sometimes is that a test suite can become brittle because it incorporates a lot of assumptions. Some pieces of code perform conceptually simple high-level functions, but are complicated enough to require elaborate interior structure. The interior subsystems don’t stand alone—they don’t really perform meaningful operations out of context. So testing them effectively often requires setting up quite a bit of contextual data. A later change in high-level information flow can change the way the subsystems interact and break a lot of tests, even if the actual required changes to the subsystems are minimal. When this occurs, it’s not unusual to spend far more time getting the tests working again than fixing the actual code.
I’ve learned to spot the warning signs of this situation when I start setting up a lot of context for unit tests. It usually means it’s time to rethink how I’m structuring the code at a high level. Still, it’s not something I can always avoid.
Jeff: Do you have any stories about how TDD "saved the day," or helped solve a particularly difficult problem?
Jerry: We never know about most of the times that TDD saves the day! A lot of nasty bugs never occur because they’re filtered out of the code during TDD. The kinds of situations we do get to see are the ones I alluded to earlier: It’s much easier to make big changes to a code base when necessary. More than once I’ve found myself making wholesale changes and thinking, "I would never have had the confidence to make these changes in the current timeframe if I had written this code the old way."
I do think TDD helps in attacking the most difficult problems because it lets you carve off small pieces of the problem, get them working, and then forget about them. Since you have the test suite in place, you don’t have to constantly keep them in mind to make sure that you don’t violate their assumptions. It significantly reduces the cognitive load when working on something complicated.
Jeff: What has TDD taught you about development?
Jerry: I believe I’ve become more proficient at structuring software from a user’s point of view. I used to approach code by thinking about how I could "make it do x," while x was fairly loosely defined. Even when I had written or received functional specifications up front, there was still enough fog around the actual use of the software to lead to issues down the road. Now I am a user of the code and I’m exposed to all sorts of interaction and use issues early enough to deal with them effectively.
Also, I’ve discovered I’m not as smart as I thought I was. [He grins.] I used to assume I could keep a whole system in my head despite the fact that I would have to go back and rediscover it when I had bugs to fix. Now when I go back and look at tests, I realize I would never have remembered, on my own, all the subtleties they embody.
Jeff: What are some of the things your co-developers value in TDD?
Jerry: Mostly the same things I do, I think. We’ve done enough talking about it among us that we’ve cross-fertilized on most of the benefits.
Jeff: How has Cassatt benefited from doing TDD?
Jerry: We’ve been able to move fast and develop a lot of code with a high level of quality, and people don’t (always) have to worry about breaking things when they commit code to the codebase.
Jeff: Any additional comments?
Jerry: I think TDD is one way to forcibly inject reality into software development. Unrealistic thinking and expectations show up everywhere in the software development process. Here are some examples:
- Unrealistic belief in the correctness and detail of specifications. I’ve seen people actually surprised when development goes off course—after all, a functional specification had been done. TDD takes the specification to the next level very early in the process and exposes the fuzzy areas.
- Unrealistic expectations for the time required to produce production quality software. TDD helps prevent this problem, since it moves some of the back-end testing time into the development process, where a developer has to bid it.
- Unrealistic expectations for the future of a project. A lot of developers seem to think that software will never need to be modified—and, if it does, the original author will be the one to do it. This issue is often used as a justification for increased code documentation, but I’ve never been that impressed with how much value is added by excessive commenting. Comments can get out of sync with code and are often simply translations from code into English, anyway. Tests developed via TDD, by definition, cover all the behavior of the code and can’t get out of sync. A good test suite is a much better hedge against future change than some extra comments.
Jeff: Thanks, Jerry! Best of luck to you and Cassatt.