Effective Unit Testing
A guide for Java developers
Lasse Koskela
  • February 2013
  • ISBN 9781935182573
  • 258 pages
  • printed in black & white

A fantastic, definitive guide. It will boost your productivity and deployment effectiveness.

Roger Cornejo, GlaxoSmithKline

Effective Unit Testing is written to show how to write good tests—tests that are concise and to the point, expressive, useful, and maintainable. Inspired by Roy Osherove's bestselling The Art of Unit Testing, this book focuses on tools and practices specific to the Java world. It introduces you to emerging techniques like behavior-driven development and specification by example, and shows you how to add robust practices into your toolkit.

Table of Contents show full



about this book

about the cover illustration

Part 1 Foundations

1. Chapter 1 The promise of good tests

1.1. State of the union: writing better tests

1.2. The value of having tests

1.3. Tests as a design tool

1.4. Summary

2. Chapter 2 In search of good

2.1. Readable code is maintainable code

2.2. Structure helps make sense of things

2.3. It’s not good if it’s testing the wrong things

2.4. Independent tests run easily in solitude

2.5. Reliable tests are reliable

2.6. Every trade has its tools and tests are no exception

2.7. Summary

3. Chapter 3 Test doubles

3.1. The power of a test double

3.2. Types of test doubles

3.3. Guidelines for using test doubles

3.4. Summary

Part 2 Catalog

4. Chapter 4 Readability

4.1. Primitive assertions

4.2. Hyperassertions

4.3. Bitwise assertions

4.4. Incidental details

4.5. Split personality

4.6. Split logic

4.7. Magic numbers

4.8. Setup sermon

4.9. Overprotective tests

4.10. Summary

5. Chapter 5 Maintainability

5.1. Duplication

5.2. Conditional logic

5.3. Flaky test

5.4. Crippling file path

5.5. Persistent temp files

5.6. Sleeping snail

5.7. Pixel perfection

5.8. Parameterized mess

5.9. Lack of cohesion in methods

5.10. Summary 113

6. Chapter 6 Trustworthiness

6.1. Commented-out tests

6.2. Misleading comments

6.3. Never-failing tests

6.4. Shallow promises

6.5. Lowered expectations

6.6. Platform prejudice

6.7. Conditional tests

6.8. Summary

Part 3 Diversions

7. Chapter 7 Testable design

7.1. What’s testable design?

7.2. Testability issues

7.3. Guidelines for testable design

7.4. Summary

8. Chapter 8 Writing tests in other JVM languages

8.1. The premise of mixing JVM languages

8.2. Writing unit tests with Groovy

8.3. Expressive power with BDD tools

8.4. Summary

9. Chapter 9 Speeding up test execution

9.1. Looking for a speed-up

9.2. Speeding up test code

9.3. Speeding up the build

9.4. Summary

Appendix A: JUnit primer

Appendix B: Extending JUnit


© 2014 Manning Publications Co.

About the book

Effective Unit Testing teaches Java developers how to write unit tests that are concise, expressive, useful, and maintainable. Offering crisp explanations and easy-to-absorb examples, it introduces emerging techniques like behavior-driven development and specification by example.

Programmers who are already unit testing will learn the current state of the art. Those who are new to the game will learn practices that will serve them well for the rest of their career.

What's inside

  • A thorough introduction to unit testing
  • Choosing best-of-breed tools
  • Writing tests using dynamic languages
  • Efficient test automation

About the author

Lasse Koskela is a coach, trainer, consultant, and programmer. He hacks on open source projects, helps companies improve their productivity, and speaks frequently at conferences around the world. Lasse is the author of Test Driven, also published by Manning.

combo $39.99 pBook + eBook
eBook $31.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

Changed the way I look at the Java development process. Highly recommended.

Phil Hanna, SAS Institute, Inc.

A common sense approach to writing high quality code.

Frank Crow, Sr. Progeny Systems Corp.

Extremely useful, even if you write .NET code.

J. Bourgeois, Freshly Coded

If unit tests are a nightmare for you, read this book!

Franco Lombardo, Molteni Informatica