liveBook · Manning

Naming standard

As explained in Unit Testing Principles, Practices, and Patterns

A test naming policy is a set of rules governing how tests are named to communicate their scenarios and intent.

A test naming policy makes each test communicate the scenario it verifies and the behavior expected from the system. Plain-English names preserve that meaning for programmers and domain experts, while rigid method-scenario-result templates often expose implementation details and impose a cognitive tax. section 3.4

Apply these practical rules:

  • Describe the scenario as a domain behavior rather than repeating the method under test. section 3.4
  • Write names as if explaining the scenario to a non-programmer familiar with the problem domain. section 3.7
  • Separate words with underscores, and accept that parameterized tests may reduce name readability when generalized. section 3.7

Refactoring a delivery test name

Replace IsDeliveryValid_InvalidDate_ReturnsFalse with Delivery_with_past_date_is_invalid. The latter states the observable business behavior without repeating the method name or using unexplained “Returns” phrasing. section 3.4

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Contrasts rigid templates with plain-English names and demonstrates refactoring, but does not examine naming automation or tooling.
Examples
Uses calculator addition and delivery validation tests to contrast rigid names with plain-English behavioral names.
What it assumes
Assumes familiarity with unit tests, tested methods, scenarios, and expected results.
What you can do after
Apply it by renaming tests around observable scenarios, domain language, and expected behavior rather than method signatures.
How it connects
Connects test naming with unit testing, test readability, domain language, implementation details, and parameterized tests.

Also explained in

Compare how 8 books explain naming standard →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.