2.7.12 Revising Code From Test Evidence

Revising Code From Test Evidence

Use accepted and rejected temperature changes as evidence when revising the Wildcats application. Fix the behavior the evidence identifies, then check that other required behavior remains intact.

Start with explicit expectations

Use the validated TrainingArea implementation as the intended contract.

Independent checks on a fresh area
Action Expected temperature
Create area 20.0
Increase once 20.5
Decrease once 19.5
Increase ten times 25.0
Increase eleven times 25.0
Decrease eleven times 15.0

Recreate the area before each table row. Otherwise earlier actions change the starting state and make the expected result inappropriate.

Use a boundary failure to locate the cause

Suppose the setter accidentally uses strict comparisons. This fragment is intentionally faulty; it would replace the correct setter condition.

Intentional boundary defect
if (value > 15.0 && value < 25.0)
{
    this.temperature = value;
}

After nine increases the value is 24.5. The tenth proposes 25.0 but is rejected. That observation points to excluding the endpoint. Change the comparisons to >= and <= to match the inclusive contract.

Repeat focused checks and regression checks
  1. Reproduce the failure with a known starting state.
  2. Inspect the proposed value and condition in the debugger.
  3. Make the smallest change that implements the stated rule.
  4. Repeat the failing endpoint check and the just-outside rejection check.
  5. Repeat normal increase, decrease, and creation checks to detect unintended effects.
Apply the idea
Check your understanding