Java Reference
In-Depth Information
when I was upside-down in the middle of a Class V- rapid in Colorado, I
needed to know that my roll would work. Two things helped me hit that roll.
The first was repeated use, or testing; the second was organization. Though it
would be silly to test my roll in all different contexts, I did spend time perfect-
ing my roll in turbulent water. I also spent time organizing my strategy. I knew
to hold my paddle with the right wrist, rolled forward, next to my left knee. I
knew to keep my head to my chest and my nose to the deck for protection.
When the time came, it worked. These standards and tips can help us do the
same thing for software. Some of the tips come from XP practices. Others
come from coding conventions that I've used throughout my career.
Code unit tests first. XP recognizes the value of embracing testing. Cod-
ing the tests helps us to consider exceptions when we design our classes.
It helps us design all the way, code all the way, and test all the way. With
a more accurate assessment of what we're building, we can even pro-
duce better schedules.
Include a main for unit tests. Using a main can help when testing some
stand-alone classes with the command line, to make sure that they fit
specifications.
Organize test cases. Some organizations will want to build test cases into
the classes themselves, and some will want externally driven classes. Scaf-
fold as necessary.
Append built-in test methods with a keyword like test . It is important to
be able to identify test cases versus production code for many reasons,
and this practice helps us identify the tests quickly.
A combination of good design, effective test organization, and discipline will
ensure that our classes perform when we need them. A first-rate unit testing
application, such as JU nit or HTTPU nit, will make some of these steps unnec-
essary and will enforce others. Testing methodologies go well beyond the
scope of coding conventions, or even this topic. Many books are available that
can supplement your knowledge on the subject, including:
Testing Object-Oriented Systems: Models, Patterns, and Tools (The Addi-
son-Wesley Object Technology Series), by Robert V. Binder
Object-Oriented Software Testing: A Hierarchical Approach , by Shel Sie-
gel and Robert J. Muller
Search WWH ::




Custom Search