Java Reference
In-Depth Information
Some programmers like this type of repetitive testing. It can be a pleasant break
from deep thought and hardcoding. When our little click-through tests finally suc-
ceed, there's a feeling of accomplishment: Eureka! I found it!
Other programmers dislike this type of repetitive work. Rather than run the test
by hand, they prefer to create a small program that runs the test automatically. Play-
testing code is one thing; running automated tests is another.
If you're a play-test developer, this topic is for you. We'll show you how creating
automated tests can be easy, effective, and even fun.
If you're already “test-infected,” 1 this topic is also for you. We cover the basics in
part 1 and then move on to the tough, real-life problems in parts 2, 3, and 4.
1.1
Proving it works
Some developers feel that automated tests are an essential part of the development
process: you can't prove a component works until it passes a comprehensive series of
tests. Two developers felt that this type of unit testing was so important that it deserved
its own framework. In 1997, Erich Gamma and Kent Beck created a simple but effec-
tive unit testing framework for Java, called JU nit. Their work followed the design of an
earlier framework Kent Beck had created for Smalltalk, called SU nit.
DEFINITION A framework is a semi-complete application. 2 A framework pro-
vides a reusable, common structure to share among applications. Developers
incorporate the framework into their own application and extend it to meet
their specific needs. Frameworks differ from toolkits by providing a coherent
structure, rather than a simple set of utility classes.
If you recognize those names, it's for good reason. Erich Gamma is one of the Gang of
Four who gave us the now-classic Design Patterns topic. 3 We know Kent Beck equally
well for his groundbreaking work in the software discipline known as Extreme Pro-
gramming ( http://www.extremeprogramming.org) .
JU nit ( http://www.junit.org) is open source software, released under IBM 's Com-
mon Public License Version 1.0 and hosted on SourceForge. The Common Public
License is business friendly: people can distribute JU nit with commercial products
without a lot of red tape or restrictions.
JU nit quickly became the de facto standard framework for developing unit tests in
Java. The underlying testing model, known as xUnit, is on its way to becoming the
standard framework for any language. There are xUnit frameworks available for ASP ,
C++, C#, Eiffel, Delphi, Perl, PHP , Python, REBOL , Smalltalk, and Visual Basic—to
name a few!
1
Te s t - i n f e c t e d is a term coined by Gamma/Beck, “Test-Infected: Programmers Love Writing Tests,” Java Report , 3, 7, 37-
50: 1998.
2
Ralph E. Johnson and Brian Foote, “Designing Reusable Classes,” Journal of Object-Oriented Programming 1.5
(June/July 1988): 22-35; http://www.laputan.org/drc/drc.html.
3
Erich Gamma et al., Design Patterns (Reading, MA: Addison-Wesley, 1995).
 
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search