The Artima Developer Community

Artima Chapters Library
Pragmatic Unit Testing
in Java with JUnit
by Andy Hunt and Dave Thomas

Please login to download the free chapter for this book.

Download a Free Chapter

Chapter 1
Introduction
Please login to download.

Buy the Book

About the Book

Book Description
Table of Contents
Book Reviews and Discussion
ISBN: 0974514012
Publisher: Pragmatic Bookshelf
Publication Date: 2003
Edition: 1st
Binding: Paperback
Number of Pages: 176

Pragmatic programmers use feedback to drive their development and personal processes. The most valuable feedback you can get while coding comes from unit testing.

Without good tests in place, coding can become a frustrating game of "whack-a-mole." That's the carnival game where the player strikes at a mechanical mole; it retreats and another mole pops up on the opposite side of the field. The moles pop up and down so fast that you end up flailing your mallet helplessly as the moles continue to pop up where you least expect them.

You don't test a bridge by driving a single car over it right down the middle lane on a clear, calm day. Yet many programmers approach testing that same way --- one pass right down the middle and they call it "tested." Pragmatic programmers can do better than that!

Real unit testing will make your life easier. It will make your designs better and drastically reduce the amount of time you spend debugging.

Table of Contents

1 Introduction 
  1.1 Coding With Confidence 
  1.2 What is Unit Testing? 

  1.3 Why Should I Bother with Unit Testing? 
  1.4 What Do I Want to Accomplish? 
  1.5 How Do I Do Unit Testing? 
  1.6 Excuses For Not Testing 
  1.7 Roadmap 
2 Your First Unit Tests 
  2.1 Planning Tests 
  2.2 Testing a Simple Method 
  2.3 More Tests 
3 Writing Tests in JUnit 
  3.1 Structuring Unit Tests 
  3.2 JUnit Asserts 
  3.3 JUnit Framework 
  3.4 JUnit Test Composition 
  3.5 JUnit Custom Asserts 
  3.6 JUnit and Exceptions 
  3.7 More on Naming 
  3.8 JUnit Test Skeleton
4 What to Test: The Right-BICEP 
  4.1 Are the Results Right? 
  4.2 Boundary Conditions 
  4.3 Check Inverse Relationships 
  4.4 Cross-check Using Other Means 
  4.5 Force Error Conditions 
  4.6 Performance Characteristics 
5 CORRECT Boundary Conditions 
  5.1 Conformance 
  5.2 Ordering 
  5.3 Range 
  5.4 Reference 
  5.5 Existence 
  5.6 Cardinality 
  5.7 Time 
  5.8 Try It Yourself 
6 Using Mock Objects 
  6.1 Simple Stubs 
  6.2 Mock Objects 
  6.3 Testing a Servlet 
  6.4 Easy Mock Objects 
7 Properties of Good Tests 
  7.1 Automatic 
  7.2 Thorough 
  7.3 Repeatable 
  7.4 Independent 
  7.5 Professional 
  7.6 Testing the Tests 
8 Testing on a Project 
  8.1 Where to Put Test Code .
  8.2 Test Courtesy 
  8.3 Test Frequency 
  8.4 Tests and Legacy Code 
  8.5 Tests and Reviews .
9 Design Issues 
  9.1 Designing for Testability 
  9.2 Refactoring for Testing 
  9.3 Testing the Class Invariant 
  9.4 Test-Driven Design 
  9.5 Testing Invalid Parameters 
Appendix A: Gotchas
Appendix B: Installing JUnit
Appendix C: JUnit Test Skeleton 
Appendix D: Resources
Appendix E: Summary
Appendix F: Answers to Exercises

Review this Book

Readers have already posted 1 comment about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Pragmatic posts a new announcement, subscribe to this RSS feed.

About Pragmatic Bookshelf

The Pragmatic Bookshelf features books written by developers for developers. The titles continue the well-known Pragmatic Programmer style, and continue to garner awards and rave reviews. As development gets more and more difficult, the Pragmatic Programmers will be there with more titles and products to help programmers stay on top of their game.

This page is Copyright © 2004 Pragmatic Bookshelf. All rights reserved.



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use