View all services
Talk to QA Advisor
Browse the Knowledge Hub211 resources
/Books/Unit Testing Principles, Practices, and Patterns
Books · Honest notes

Unit Testing Principles, Practices, and Patterns: is it worth reading?

The clearest modern account of what makes a unit test valuable, and why most suites are full of tests that are not.

We earn nothing from any link on this page. No affiliate links anywhere in this library.

published
2020
key ideas
3
reading path
1

Reviewed by Viral Patel

Co-Founder, QAble

Cover of Unit Testing Principles, Practices, and Patterns
Unit testing & TDD

Unit Testing Principles, Practices, and Patterns

by Vladimir Khorikov

Publisher
Manning
Year
2020
ISBN
9781617296277

Useful when you are: Practising tester, Senior / lead

Verdict

Should you read it?

Read it if

You write or review unit tests, or you have a suite with high coverage that nobody trusts. It explains that specific pathology better than anything else available.

Skip it if

You do not write code. The examples are C sharp and the arguments are code-level throughout.

If you only read one thing

The chapter on the four pillars. It gives you a rubric you can apply to any existing test in about thirty seconds.

The argument

What it argues

Khorikov argues that the goal of unit testing is sustainable project growth, and that a test only contributes to that if it has four properties: protection against regressions, resistance to refactoring, fast feedback, and maintainability. The four trade off against each other, and resistance to refactoring is the one almost everyone sacrifices without realising.

The central practical argument is against testing implementation detail. A test that verifies how a class does something rather than what it produces will break on a correct refactoring, which teaches the team that failing tests are noise. That is how a suite loses its value while coverage stays high.

He is also direct about the London versus Chicago schools of TDD, and argues that heavy mocking couples tests to structure and is the main cause of refactoring-resistant suites.

Key ideas

Ideas worth taking from it

  1. 01

    The four pillars of a good test

    Regression protection, resistance to refactoring, fast feedback, maintainability. The framework for deciding whether a test is worth keeping.

  2. 02

    Resistance to refactoring

    The property nobody optimises for and the one that determines whether a suite survives. Tests coupled to implementation break on correct changes and are eventually ignored.

  3. 03

    Observable behaviour against implementation detail

    Test what a unit produces for a caller, not how it produces it. The practical rule that follows from the above and the one most suites violate.

Criticism

What has dated, and what it gets wrong

Opinionated in places where the profession genuinely disagrees, particularly on mocking and on the classical school. Readers committed to the London school will find the treatment unfair. The examples are all C sharp, which is a barrier for some, though the arguments transfer cleanly.

Reading paths

On our reading paths

Becoming an automation engineer

Book 2 of 5 · Automation and SDET

The best modern account of what makes a test valuable and when mocks help or hurt. Read it before your suite is large enough to make those mistakes expensive.

  1. Cover of Test Driven Development: By Example1. Test Driven Development: By Example
  2. Cover of Unit Testing Principles, Practices, and Patterns2. Unit Testing Principles, Practices, and Patterns (this book)
  3. Cover of Growing Object-Oriented Software, Guided by Tests3. Growing Object-Oriented Software, Guided by Tests
  4. Cover of Working Effectively with Legacy Code4. Working Effectively with Legacy Code
  5. Cover of Specification by Example5. Specification by Example

Keep reading

What to read next

Ready

Reading about quality is cheaper than learning it in production.

QAble runs QA for products in BFSI, gaming, healthcare and SaaS, with engineers who have read these and argued about them. Start with a free QA audit.

Talk to QA Advisor