Académique Documents
Professionnel Documents
Culture Documents
DON’T
JUST
BREAK How
SOFTWARE. driven
storytest-
development
MAKE ischanging
SOFTWARE. the
way
QA,
STORYTEST-DRIVEN DEVELOPMENT (STDD)
customers,
IS AN EXTREME PROGRAMMING PRACTICE.
and
The basic premise is that before developers
any code is written, a team takes work.
a story (or rough idea of a require- by Tracy Reppert
ment) and fleshes out that story by
producing an executable “story-
test.” Opponents say that STDD is
“cowboy coding,” or “snake oil,” or
PRESTON MACK / REDUX PLUS
A GLIMPSE
from being lost in abstract discussions and vague generalities.
To illustrate, let’s suppose a business has a rule that, for ac-
counting purposes, all months are treated as having thirty days.
OF STDD (Some bonds are valued under a similar rule.) One of the stories
might be “Implement the 30-day rule.” The business expert
IN ACTION. by
might write something like this on the whiteboard:
building a system that is not acceptable. THE FIRST STEP CAN helps teams obtain the necessary amount
And QA loves it because programmers BE A BIG ONE of story details when they need it—before
aren’t viewing them as the bad guys,” If STDD is so great, why do so many peo- writing code.
says Raha. ple distrust it? Perhaps some of the skep- Even now that most of the quirks
STDD challenges the notion that QA tics of STDD haven’t experienced it since have been worked out, people may still
has to play a rival role to a programming its inception. XP and STDD definitely had be wary of such a big change. “It was dif-
team if they expect to be able to spot de- some growing pains. Joshua Kerievsky ex- ficult to trust the process in the begin-
fects. In practice, teams find that they plains, “In the early days of XP, we did a ning,” says Pam Smoot, senior project
are saving a lot of time by having QA lot of unit test-driven development and manager at Nielsen Media Research,
help produce storytests from the begin- would automate storytests only after we’d which began implementing STDD for a
ning. “A tester is sometimes viewed as written our code. The trouble with this major data-warehousing project, “but it’s
an adversary, when all they are trying to approach was that it was often hard to get so much better than what we used to do.
do is ensure that the delivered product subject matter experts to define storytests, Having expected results created upfront
functions well,” says Merrilee Albright,
lead SQA analyst at Nielsen Media Re-
search and member of an STDD team. “It was difficult to trust
“I’ve been testing a long time, and have the process in the beginning,
found that my role on this team definite- but it’s so much better than
ly has more respect than it might in the
normal software development process. I
what we used to do.”
—PAM SMOOT
can utilize the expertise of other team
members to help me create tests. Having
the customer available to review the test which meant that with successive itera- by a business/QA person helped us find
results and make suggestions immediate- tions we would get further and further be- miscalculations, misinterpretations, and
ly has proved invaluable. Creating the hind on the number of storytests we still miscommunications right away rather
expected results was quite challenging, needed. That produced higher defects, than late in the project.”
but it was rewarding when they ran and since the lack of sufficient story details led Skeptics begin to see the value of
ensured that the system was functioning to code that failed to fully satisfy customer STDD in just a couple of weeks, accord-
as expected.” expectations.” He adds that STDD now ing to Smoot, though it can take a few
CONVERSATIONAL EXAMPLES
BECOME STORYTESTS
Once the iteration is planned, it’s the job of the programmers
to produce features that satisfy the business expert, and it’s
the job of the business expert to support them—mainly by be-
ing available for further conversation. For example, a program-
getting those tests to pass, other people can contin-
ue writing tests. The test-driven style is to make tests
pass one at a time; while working on one test, the
programmer doesn’t worry overmuch about what
tests remain. So it doesn’t matter if some of those
tests are not yet known. These storytests do not necessarily
>
continued
mer might realize that she doesn’t know what the program completely replace conventional testing. They’re designed to
should do in some special case, so the business expert has to build quality into the product. Someone else still needs to cre-
tell her. Or a programmer might realize that the code is so ate tests to detect where the storytests fell short of the goal
structured that it would be trivial to add a new wrinkle to the of preventing bugs.
feature, so the business expert should tell her if the new wrin-
kle is a good idea.
The business expert should also help with the tests. The CalendarFixture
table at right shows a starting set of tests that came up in the from to elapsed() actual()
imaginary planning meeting we mentioned earlier. (Ignore the
1 Apr 2003 1 May 2003 30 30
first row for now.)
Who writes that table? It’s entirely up to the team. Some 1 Feb 2003 1 Mar 2003 30 28
business experts might be happy writing such tables them- 1 Jan 2003 1 Feb 2003 30 31
selves. In other cases, it might be dedicated testers or the pro-
1 Jan 2003 31 Jan 2003 30 30
grammers. What’s important is that the tests get written effi-
ciently and that the business expert believes that seeing them 1 Feb 2003 28 Feb 2003 27 27
pass will increase his confidence in the program. 1 Feb 2004 29 Feb 2004 28 28
This set of tests needn’t be complete. It need only be
1 Feb 2004 1 Mar 2004 30 29
enough for the programmers to get started. As they work on
> continued
STORYTESTS BECOME CODE
Making a table of storytests pass requires two steps.
THE SECOND STEP is to make the test pass. In some cases (like Brian Marick has worked in testing since 1981. He is the au-
our calendar example), that’s straightforward. The programmer thor of The Craft of Software Testing, and is the technical edi-
runs the table, sees that a row fails, changes the code, runs tor for Better Software magazine. Contact Brian at marick@
the table again to see that the row now passes. testing.com. Read other writings at testing.com. (Author’s
In other cases, the changes needed to make the tests run note: Cheryl Redding and Praseed Thapparambil of Nielsen
are too large for that. Fans of test-driven design like to run Media Research, and Chris Wheeler of Sciex contributed to
tests often. They don’t like to make many changes before this series of sidebars.)
1 3
Check In Storytests
Define Stories It is best to check in storytests to your version control soft-
Work with subject matter experts and analysts to define ware as soon as they’ve been created. We do this as soon as
stories: roughly defined chunks of functionality. We typi- a storytest has been defined. When developers integrate
cally use index cards for stories. Good story headings are their code, they ought to see that new storytests have been
no longer than five words and use the active voice. For ex- checked in. This informs them that they can begin working
ample: “Book a Room,” “Calculate Capital for Term on the story(ies) associated with the checked in storytest(s).
Loan,” or “Export Risk Report into Excel” are good story In general, programmers should not begin programming a
headings. The details of a story give enough information story until they have a storytest that is failing.
for programmers to make decent time estimates for imple-
4
menting stories. For the story “Book a Room,” the details
might be “Allow user to make a reservation for a single
room, assuming no special rate discounts or late check-
outs.” For more details on how to write good stories, see
the new book User Stories Applied by Mike Cohn.
Program the Storytests
Once developers have a storytest, they will begin writing
test code to show that the storytest is failing. If the team
2
is using FIT, this involves defining the appropriate sub-
class of FIT fixture class and then delivering production
code to make the storytest pass. During this time, it is
Define Storytests typical and optimal to do unit test-driven development in
Once stories have been defined, you can begin writing conjunction with STDD. This helps you to evolve pro-
storytests. This is best done through the collaboration of duction code that has sufficient test coverage. The combi-
subject matter experts, testers or QA persons, and pro- nation of these testing techniques leads to fine-grained
grammers. A storytest helps verify that a story works cor- unit tests for classes and medium- to large-grained story-
rectly by documenting what inputs are supplied to a sys- tests for the features of the system. Throughout this
tem and what outputs are expected. A document that process, programmers check in code, unit tests, and
contains a storytest can include other useful information, storytests when they are passing.