Testing, The Ugly Stepchild of
Better Living through Software
Chris Berry – Feb 21, 2000
Chris Berry firstname.lastname@example.org
It’s easy to fool yourself.
It simply makes programming more
Test Early, Test Often
Defects are order of magnitude cheaper
to fix when programmers find their own
No communication cost.
The bug tracking system does not
The error does not block or corrupt the
work of other developers.
The Art of catching bugs before they
Programming by Contract.
The hallmark of Defensive
Allows you to assert that a particular
condition is met, and commonly, if it is
not, terminate execution.
Pre and post conditions.
Not to be confused with Exceptions.
A simple coding convention which
requires all Classes to provide a boolean
Used to determine whether a particular
Instance is in a sane state.
Low tech debugging technique. Often
the only way to debug threaded code.
Can speed development.
Can result in “Scroll-blindness”. Best to
divert logging to a file rather than
The log4j package for Java.
Test each unit of code independently.
In OO, this equates to testing a Class
and its public interface.
Involves debugging, simultaneously, the
code, the test, and the Spec.
Unit Testing is Glass Box
You Must be aware of
All branches of the method under test.
What inputs should produce what results
The interplay of affected member variables
Building a Good Unit Test
Valid input: Insure that correct outputs are
generated for correct input conditions.
Invalid input: Insures proper error
Deciding on Unit Test Input
Good partitioning gives rigor without
Things go wrong at the edges.
Expected and unexpected Exceptions.
An equivalence class is a definition of a
group of inputs, any one of which
should be treated exactly the same by
the method under test.
Eliminates redundant tests. The
behavior of the method should be
“equivalent” so only one test need be
run for any equivalence class.
The term for choosing the appropriate
values to test a particular equivalence
Choose values at the edge of the set.
Also a good idea to include the
Dealing with Exceptions
Catch all unplanned Exceptions.
Match all thrown Exceptions with the
conditions expected to produce them.
Classic Unit Test construct
Generate argument providers
Loops over all argument providers
Construct the Object under test (OUT)
Optionally save the state of the OUT
Call the method under test (MUT)
If an exception was generated
Test for unhandled exceptions
Assertions on the resultant, OUT, and
Tests which prove that the program
properly executes some required
Typically involves the integration of
Often a test from the perspective of the
“A lightweight, low-risk, flexible,
predictable, and fun way to develop
Takes commonsense best practices and
applies them to an extreme degree.
XP in a Nutshell
Code is king.
Emphasis on refactoring.
The Four Variables
The Four Values of XP
Central Principles of XP
Secondary Principles of XP
Small Initial Investment.
Play to Win.
Secondary Principles of XP,
Work with instincts.
Four Basic Activities of XP
XP Development Practices
Tests Before Code
XP Development Practices,
Testing the XP way
A simplified, pragmatic, and less rigorous
approach to testing.
Tests things that might break. Testing simple
methods, like accessors, is valueless.
Write the tests first.
Keep the tests running.
Tests are automatic. Run the full suite several
times a day.
JUnit, a Java testing framework. A C++
version (CPPUnit) is now available.
The earlier you catch a bug the less it is
going to cost you.
Testing can actually speed up your
development time, and improve your
quality of life.
XP is a pragmatic approach to writing
XP embraces change.
Some of the Slide Notes for this presentation
were lifted verbatim from several sources;
“Test Infected. Programmers Love Writing Tests”
by Eric Gamma and Kent Beck.
“eXtreme Summary - An Overview of eXtreme
Programming eXplained: Embrace Change” by
“Divide and Conquer - Preemptive and Unit
Testing” by Chris Berry
“The Pragmatic Programmer” by Andrew Hunt and