liveBook · Manning

Software testing

As explained in The Coder Cafe

A test case is a specified testing scenario with defined inputs, initial conditions, and expected results.

Testing checks whether software behaves as expected in specified scenarios. A traditional test case defines a starting state, supplies inputs, and asserts an expected result. Tests make changes less risky, but a passing case establishes only that its particular scenario passed—not that the whole system is correct. section 5.2.2 section 5.0

A useful test suite needs more than passing results:

  • Check the intended behavior. A test based on a misunderstanding can pass while documenting behavior that does not exist; a flawed assertion can miss a bug it was meant to catch. section 5.2.1
  • Keep expectations simple. Prefer a literal expected value to one calculated with logic that might repeat the implementation’s mistake. section 5.7
  • Look beyond a coverage percentage. Line coverage can miss an untested branch, while a high target can reward weak tests written merely to reach it. section 5.7

Unit tests check individual pieces of code and offer quick, local feedback. Aim for tests that are focused, understandable, deterministic, isolated, and informative when they fail. Name each test for the behavior and expected outcome, and keep it narrow enough to serve as readable documentation. Check observable behavior rather than private methods or internal state so unrelated implementation changes do not break it. section 5.3.11 section 5.4 section 5.7

Testing an array sort

For a sorting function, test an unsorted array, an already sorted array, a one-element array, and an empty array. These are distinct scenarios, not proof that every possible input works. When the expected behavior is clear, they can also guide a Red-Green-Refactor cycle: observe a failing test, write enough code to pass it, then improve the implementation while keeping it green. section 5.6 section 5.2.2

When hand-picked cases leave too much room for missed edge cases, property-based testing checks invariants, such as debits equaling credits. It complements rather than excuses careful examples. Integration tests matter too, but they tend to run more slowly and can make failures harder to diagnose than unit tests. Add tests when changing existing code; writing them before implementation is an optional workflow, not a measure of quality by itself. section 5.7 section 5.3.5 section 5.3.8

How The Coder Cafe covers it

How deep it goes
Defines a traditional test’s starting state, inputs, and assertion, then examines test quality, coverage limitations, and alternative workflows without framework instructions.
Examples
Uses array-sorting cases, a debits-equal-credits invariant, and flawed passing tests to illustrate both useful checks and false confidence.
What it assumes
Introduces the structure of a traditional test while assuming familiarity with software behavior and code changes.
What you can do after
Practice/perform behavior-focused testing while assessing assertions, coverage gaps, edge cases, and maintenance costs.
How it connects
Connects testing to unit tests, integration tests, branch coverage, property-based testing, refactoring, and test-driven development.

Also explained in

Compare how 67 books explain software testing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Coder Cafe. The section links point to the parts of the book it draws on.