small medium large xlarge

Pragmatic Unit Testing in Java with JUnit


Cover image for Pragmatic Unit Testing in Java with JUnit

Pragmatic Unit Testing in Java with JUnit


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

Let your Java code tell you what’s working and what isn’t. You’ll learn how to test using JUnit, but more importantly, you’ll learn what to test.

Pragmatic Unit Testing in Java 8 with JUnit is available here.

For various technical reasons, the eBook version is a PDF: epub and mobi versions of this title will NOT be available.

Customer Reviews

I am a firm believer in unit testing and I would want all team members I work with to be religiously practicing the techniques recommended in this book. I think there is a lot of good, practical information in this book that any professional software engineer should be incorporating into their daily work.

- James J. O'Connor III

Lead System Design Engineer

I’m not totally new to testing, but I’ve struggled with many aspects of it. I think this book does a good job of bringing those along who are completely new to unit testing, but still has enough advanced material to assist those of us who have dabbled in testing and floundered once we’ve hit obstacles.

- Andrew Thompson

Consultant, Greenbrier & Russel

When I’m on a project that needs to be doing unit testing better (which is often the case), I’d like to have this book available as a simple reference to suggest to the team.

- Bobby Woolf

Consulting IT Specialist, IBM

I wish I had a copy back when I started doing test-first development as part of Extreme Programming.

- Al Koscielny

Software Developer

This book starts out with a nice introduction discussing what unit testing is as well as why we should do it. I like the anecdotes peppered throughout the book illustrating the point of why one should bother… I also really liked the analogies you use. It puts the code into a real-world context.

- Sharee L. Johnson

Project Lead, Applications Development

This is the most approachable and cogent JUnit book I’ve read… and I’ve read them all. If you’re new to unit testing with JUnit, this book will quickly get you started out on the right foot. Indeed, in the short amount of time it takes to read this excellent book you’ll learn more than I did in a year of fumbling around.

- Mike Clark

Author, Consultant,

It is the best introduction to unit testing that I’ve ever read! Excellent!

- Maik Schmidt

Software Developer, ATX Europe

See All Reviews

About this Title

Pages: 160
Published: 2003-09-01
Release: P7.0 (2010-01-06)
ISBN: 978-0-9745-1401-7

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.

With this book, you’ll:

  • Write better code, faster
  • Discover the best hiding places where bugs breed
  • Learn how to think of all the things that could go wrong
  • Test pieces of code without using the whole project
  • Use JUnit to simplify your test code
  • Test effectively with the whole team


Andy Hunt and Dave Thomas, partners in The Pragmatic Programmers LLC, and founders of the Pragmatic Bookshelf, offer pragmatic resources for developers and managers. Their first book, The Pragmatic Programmer: From Journeyman to Master, is a popular overview of techniques and practices that make programming effective and enjoyable.