An Interview with Stephen Vance, Author of "Quality Code: Software Testing Principles, Practices, and Patterns"
- Jan 21, 2014
Lisa Crispin: Given that there are already several books on TDD and automated unit testing, what's different about your book?
Stephen Vance: Although I'm a big fan of TDD, the book is really about the mechanics of bringing code under test for automation and what testable designs and code look like--implementation patterns for code-level testing if you will. While existing books touch on the techniques, they do it while trying to convey a different point and only touch my content incidentally and incompletely. I've found the mechanics to repeatedly be the missing ingredient for people trying to write code-level tests.
Lisa: That's a good point. When I've worked on teams that had to learn TDD, the programmers really struggled. It took them several months to get traction, and years to feel they were really good at it. Will your book ease the path over the "hump of pain" (as Brian Marick put it) of learning?
Stephen: It addresses a piece of the TDD learning curve but certainly not all of it. I've found that different people struggle with different aspects of TDD. Newer programmers don't have enough experience in using good APIs and so struggle to create them through tests. Others think in terms of the implementation, a tendency reinforced by much of our computer science educational system in my opinion; rather than their intent, which is why I wrote two chapters addressing issues of intent with examples. There's a big tendency in our craft to try to eat the whole enchilada, whereas TDD is about consuming it in nibbles. The bottom line is that TDD is a skill independent of your ability to code, conceptualize solutions, design algorithms, or any of the other skills we associate with the craft of software. Ultimately, the best way to learn TDD is to pair with someone experienced in it, which is why I like approaching it from a player/coach position after a little bit of educational introduction to TDD.
Lisa: You make an excellent point about pairing. My current team pairs 100% for writing production code, using TDD. New team members have commented how fast this got them up to speed. But I still hear a lot of push back against pairing in the community. People still say, "Oh, that would be too expensive, two people doing the job of one" or "I can't pair all the time, I need time to think and research on my own." If someone read your book and said, "I think my team should start pairing to master TDD, but our manager won't let us," what would you tell them?
Stephen: Your question gives me quite a chuckle. Pairing has to be one of the most polarizing topics among developers these days. While I'm a big fan of pairing and it works well for me personally, I'll be the first to admit that it's not best for all people or situations. The best reason to have everyone pair 100% is to give them the experiential knowledge of when pairing works and doesn't so they can base their decisions more on the work than their discomfort. I tell people that pairing is one of the most intimate things you can do while programming, and that's a big part of the discomfort often experienced when starting with it.
Without going on any more of a tangent, though, I would have a couple of responses to that question. First, regardless of what you think about pairing, it can be one of the best ways to share knowledge and skills when done effectively. I would also probe into the manager's reasons. Are they supportive of TDD? Do they think that formal training would be better? Do they have another plan to share the skill? Are there mitigating circumstances that make them want to defer the hit of any learning curve such as a tight deliverable deadline? Does the manager trust the team to make the right decisions about producing a quality product?
Lisa: Would you recommend that testers read your book?
Stephen: The target audience is people who are doing hard-core TDD. Someone doing code-level testing will get a lot out of this.
Lisa: Will it also help people doing ATDD?
Stephen: Yes, but some of the techniques are fairly low-level. Others are more general and can apply across the whole range of testing granularities.
Lisa: Tell me more about the craftsmanship angle. Why is this important?
Stephen: In our industry, people generally feel the need to rewrite code every three or so years. Craftsmanship is about writing sustainable software, so you don't have to throw it out and rewrite it.
Lisa: How do you judge if you crafted your code well enough?
Stephen: Artists say that a painting is done when you stop working on it. While that may be somewhat true in software, we have a significant and immediate financial accountability most of the time.
Let computers do what computers do best. Use all the static analysis and coverage tools at your disposal to catch bugs, check your style, and give you feedback on the thoroughness of your testing. Configuring these tools gives you a benchmark in a few dimensions of craftsmanship. That lets you focus on the design and architecture, the aspects we don’t have as much automated support for.
Lisa: Tell me why it appears to be so difficult for developers to learn how to do TDD.
Stephen: Oftentimes, people don't know what testable software looks like. Two chapters of Quality Code are dedicated to intent, because in order to do TDD well, you have to conceive what you’re writing from the outside in, not the inside out. Computer scientists aren't trained to look first at "What is the form this should take for someone to want to use to solve this problem?” They immediately start thinking about for loops, data access and SQL queries rather than usable interfaces and behaviors.
Lisa: In my experience, developers who learned TDD still were writing bad code--they realized that years later. Is there no way around this? If they read your book would they avoid this?
Stephen: It would help. People think they know how to code, so they must know how to test, and how to test-drive. Although you use programming in order to unit test and test-drive, these are separate skills. Test-driving is a skill. Test-driving leverages programming and unit testing, unit testing leverages programming.
Similarly, people say, "We're going to adopt agile," and really they're saying, "We're going to learn 20 skills simultaneously and become experts." This goes against what we know about the idea of needing 10,000 hours of practice to become an expert. Their expectations are just wrong.
They need to start out by saying "I need to learn this new skill, test-driving, which I don't have yet." By focusing on this skill they can learn it faster.
I teach TDD with simple code katas because they’re ostensibly so easy; you don't have the distraction of the complexity of the problem to take you away from the application of the skill. Programmers think they already know how to code Fizz-Buzz, and they realize it's not really that easy. A couple days’ practice with increasingly difficult katas allows them to start learning how to work with their production code. But they still need a lot of coaching and mentoring on how to apply it to production going forward.
It's hard to find anyone who already knows how to do this, and even harder to get those people to work for you. It is much like the old C++ adage: “Of the 10 best C++ programmers, nine work for AT&T and the other doesn’t work for you.”
Lisa: What do you think about Code Retreats? Do they teach test driving?
Stephen: It depends on the variety of participants. The structure of it and the participants affect the success, but they certainly promote paired test-driving. But to me, Code Retreat is about practice. How can programmers practice? Go back to your katas all the time. It’s like practicing the fundamentals of any activity. Even professional baseball players practice the fundamentals of hitting and fielding all the time.
Lisa: Do you let your programmers do this on company time?
Stephen: Absolutely. The hardest thing is getting people to realize that they need to do katas, and that it's useful. I try to reinforce that in training and coaching. "This particular kata might be good to practice that kind of thing." I like to build professional development time into their schedules so people can practice their craft without inflicting their learning time on production code.
Lisa: How do you pick what to "shave off"?
Stephen: Teams need to discuss this. When they need to change a part of the app, they need to answer some questions. Will it lay the foundation for creating new features quickly? Or is it something that won't change, or maybe something that shouldn't even be done in code? It comes down to understanding your business and having good collaboration so you can decide priorities and make decisions.
That said, tightly coupled implementations and bridging disparate technologies suggests more of an outside-in, “peel the onion” approach. Understanding your dependencies is key.
Lisa: Is it important to educate business executives and managers on the importance of craftsmanship and quality?
Stephen: Yes, but it can be challenging.
Lisa: How do you do that?
Stephen: I don't really have a fixed technique for this because so much depends on their starting attitude. Sometimes you have to gamble that you can prove it's worthwhile before they discover you're doing things differently. I think a lot of this is due to so many people doing utilization thinking instead of flow thinking: "If I keep all my developers 100% busy I will be better off."
It’s really about streamlining the delivery of value, but we haven't figured out how to measure value, especially over long periods of time. The total cost of software justifies the sustainability, which justifies the craftsmanship, but we usually don't measure this.