Writing a Regression Test for a Fixed Defect

A regression test uses input that once failed and asserts the observable behavior supplied by the fix.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Verify that it detects the defect
  2. Assert the promise
  3. Demonstrate that the old behavior actually fails the check
  4. Assert the promised result

Verify that it detects the defect

If an aggregate previously lost its last row, write a small case that expects the sum to include that row. Confirm the test fails against the old behavior for the intended reason. A minimal failing input keeps that cause apparent.

Assert the promise

The test should focus on the resulting total and relevant error state. An assertion tied to a helper's exact internal calls can resist harmless refactoring. Use the postcondition to decide which facts must survive implementation changes.[1]

Demonstrate that the old behavior actually fails the check

An exporter used to omit a final record lacking a newline. Preserve an input containing A followed by a terminator and B without one. The test should expect both records, which distinguishes the repaired behavior from the earlier output containing only A. See end-of-file detection.

Fixture bytes: A LF B
Earlier output: [A]
Expected repaired output: [A,B]

Assert the promised result

A later reader may correctly use a different iteration method. A test requiring a particular internal method establishes a brittle constraint. Run a paired test with a final newline to preserve compatibility with common inputs.

References

  1. Python Software Foundation, unittest: Unit Testing Framework ↩