Supplemental files and examples for this book can be found at http://examples.oreilly.com/9780596006891/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices.
All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, weve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to .
Preface
This book presents a comprehensive review of the xUnit family of unittest frameworks, including their usage, architecture, and theory. Webegin by building a simple unit test framework from the ground up.The xUnit architecture is presented, using theJUnit framework as thereference implementation of xUnit. We progressively build an exampleapplication to demonstrate common practices and patterns of unit testdevelopment. Several popular versions of xUnit, including JUnit,CppUnit, NUnit, PyUnit, and XMLUnit, are covered in detail. Detailedclass references are provided for JUnit and CppUnit as appendixes.
As a software development methodology, unit testing incorporates manyrules and guidelines. However, writing unit tests is an art, not ascience. Once you are familiar with the unit test driven approach todevelopment, rigidly following its rules is optional. The true valueof unit testing is in the focus on low-level software quality itgives developers, rather than as a formal process.
Audience
This book is intended for software developers, technical managers,and quality assurance staff who are learning about unit testing andagiledevelopment. Agile development is the wave of the future in softwareengineering, and many technical organizations are adopting it. Usingunit test frameworks to enable test driven development is a key tobecoming agile.
Contents of This Book
Here is a summary of the topics covered in each chapter and appendix:
An overview that explains what unit test frameworks are and how theyare used.
A tutorial that creates a simple Java test framework. This providesthe fundamentals of how unit test frameworks work. Appendix Acontains the C++ version of this simple framework tutorial.
A review of xUnit, using JUnit as a reference implementation todemonstrate basic xUnit architecture and usage.
An overview of writing unit tests. This offers a more detaileddiscussion of different types of unit tests and patterns of unit testdevelopment.
A discussion of unit testing of GUI applications. This chapterexplains how to build and test GUI objects following the smart objectmodel.
A description of the details of the usage and architecture of JUnitfor Java.
A description of the details of the usage and architecture of CppUnitfor C++.
A description of the details of the usage and architecture for NUnitfor .NET.
A description of the details of the usage and architecture of PyUnitfor Python.
A description of the details of the usage and architecture of XMLUnitfor XML.
A list of additional resources for unit test frameworks and relatedtopics.
The C++ version of the simple unit test framework from .
A detailed class reference for JUnit's key packagejunit.framework.
A detailed class reference for CppUnit.
Glossary
A list of definitions for important technical terms used in this book.
Conventions Used in This Book
The following typographical conventions are used in this book:
Plain textIndicates regular text and descriptions.
Constant width
Indicates commands, methods, attributes, data types, class names, orthe output from commands. It also shows the actual source code.
ItalicIndicates new terms where they are defined, pathnames, filedirectories, filenames, and Internet names, such as email addresses,and URLs.
Constant Width Bold
Indicates source code that is being emphasized for your attention.
Code in this book is formatted as shown here to distinguish it fromthe rest of the text. Code examples begin with the filename where thecode resides.
MyClass.java public class
MyClass { myMethod( ) { int id = 3; }}
Using Code Examples
This book is here to help you get your job done. In general, you mayuse the code in this book in your programs and documentation. You donot need to contact us for permission unless you'rereproducing a significant portion of the code. For example, writing aprogram that uses several chunks of code from this book does notrequire permission. Selling or distributing a CD-ROM of examples fromO'Reilly books does requirepermission. Answering a question byciting this book and quoting example code does not requirepermission. Incorporating a significant amount of example code fromthis book into your product's documentation doesrequire permission.
We appreciate, but do not require, attribution. Anattribution usually includes the title,author, publisher, and ISBN. For example:" Unit Test Frameworks , by PaulHamill. Copyright 2005 O'Reilly Media, Inc.,0-596-00689-6."
If you feel your use of code examples falls outside fair use or thepermission given above, feel free to contact us at.
How to Contact Us
Please address comments and questions concerning this book to thepublisher:
O'Reilly Media, Inc. |
1005 Gravenstein Highway North |
Sebastopol, CA 95472 |
(800) 998-9938 (in the United States or Canada) |
(707) 829-0515 (international or local) |
(707) 829-0104 (fax) |
We have a web page for this book, where we listerrata, examples, and any additional information. You can access thispage at:
http://www.oreilly.com/catalog/unitest/ |
To comment or ask technical questions about this book, send email to:
For more information about our books, conferences, Resource Centers,and the O'Reilly Network, see our web site at:
Acknowledgments
My sincere thanks go out to my reviewers: Ron Jeffries, JamesNewkirk, Philip Plumlee, J. B. Rainsberger, Simon Robbie, and AnthonyWilliams. Their shared experience and advice was incredibly usefuland encouraging. This book could not have been completed withouttheir help.
This book is built on the work of software pioneers. Kent Beck is theoriginal author of the xUnit architecture in the form ofSmalltalkUnit. Ward Cunningham, Kent Beck, and Ron Jeffriesare the formulators of the Extreme Programming methodology, which ledto many of the test driven development practices described in thisbook. Erich Gamma and Kent Beck ported SmalltalkUnitto Java to createJUnit, the most widelyused and extended unit test framework. Many individual developerscreated and contributed to the different versions of xUnit, which areclassic examples of open source software, built by the collectiveefforts of the software development community. The fingerprints ofthese talented engineers are all over the material covered by thisbook.