liveBook · Manning

Tautology test

As explained in Unit Testing Principles, Practices, and Patterns

A tautology test is a test arranged to always pass or containing assertions with no meaningful semantic check.

A tautology test is arranged to always pass or contains assertions with no meaningful semantic check. It may execute quickly and resist refactoring, but it provides no protection against regressions. section 4.4

Prevent tautological checks by following these rules:

  • Assert against an independent set of test literals or constants rather than reusing production values. section 9.3
  • Check observable behavior instead of merely repeating an assignment or encoding implementation details. section 4.4

A trivial test becoming tautological

A test that assigns "John Smith" to User.Name and immediately asserts that the property returns "John Smith" exercises almost no behavior; it can pass without protecting meaningful functionality. section 4.4

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Defines the failure mode and contrasts its speed and refactoring resistance with its lack of regression protection.
Examples
Uses a User.Name assignment-and-assertion test as a concrete example of a semantically weak check.
What it assumes
Assumes familiarity with unit tests, assertions, regression protection, and refactoring resistance.
What you can do after
Diagnose assertions that merely duplicate setup or production values and replace them with independent behavioral checks.
How it connects
Connects tautology tests with trivial tests, brittle tests, regression errors, false positives, and refactoring.

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.