Testing and Debugging
-
Choosing Boundary Test Cases
A boundary test checks the values at and immediately around a place where the intended outcome changes.
-
Reproducing an Ordinary Program Bug
A useful reproduction specifies the initial state, exact input, observed behavior, and expected outcome for a single defect.
-
Finding a Smaller Failing Input
Reduce a failing input by removing features whose presence is unnecessary for observing the same defect.
-
Separating Setup, Action, and Assertion in Tests
A test is easier to review when it establishes useful state, performs one operation, and checks the behavior that operation promises.
-
Making Test Inputs Explain Themselves
A test's values should make its assumed units, boundary, and expected result apparent to a reader.
-
Table-Driven Tests
A table-driven test enumerates inputs and expected outcomes in rows while sharing one execution and assertion procedure.
-
Independent Tests and Fresh Fixtures
Tests should establish the state they rely on so running one case independently produces the same outcome as running the suite.
-
Using Assertions to Debug Data Flow
A debugging assertion records an expected property at a point where a wrong value can still be connected to its cause.
-
Stepping Through Calls in a Debugger
A debugger can continue over a call as one step, enter it to inspect parameters, or run until its current frame returns.
-
Unit Tests and Integration Tests
A unit test checks a focused component's behavior. An integration test exercises a boundary between cooperating components.
-
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.
-
Testing Time-Dependent Code with a Fake Clock
A fake clock supplies controlled times to a routine so a test can cross a deadline without sleeping or changing the system time.
-
Testing a Reader with In-Memory Input
An in-memory input can exercise parsing behavior while avoiding files when the reader accepts a stream or iterable.
-
Capturing Output in a Test
Capture output when writing text is part of the public behavior. Inspect return values directly when they carry the result.
-
Property Tests for Sorting
A sort can be tested over generated lists by checking order and preservation of multiplicities independently.
-
Round-Trip Tests for Encoders and Decoders
A round-trip test encodes a value and decodes the result to verify that the intended information survives.
-
Metamorphic Tests with Related Inputs
A metamorphic test checks how an output should change when the input undergoes a known transformation.
-
Specifying Tolerances in Numeric Tests
An approximate test needs a tolerance derived from the input units, expected scale, and error budget of the computation.
-
Recording Random Choices in Tests
A randomized test should preserve a failing example or enough information to reproduce it under the stated environment.
-
Choosing Context for Diagnostic Logs
A diagnostic message is useful when it connects a relevant operation with the observed state and a clear result.
-
Detecting Order Dependence in Flaky Tests
A flaky test can depend on prior state, timing, environment differences, or nondeterministic execution. Narrow the cause with deliberate changes.
-
Naming Tests by Scenario and Outcome
A useful test name states the situation and the expected behavior so a failure can be understood outside the file.
-
Testing an Expected Exception
Check the promised exception near the exact operation that should raise it. Preserve enough context to distinguish it from unrelated failures.
-
Statement and Branch Coverage
Coverage indicates which code ran during tests. Branch coverage checks whether the alternatives of a decision were traversed.
-
Choosing a Hand Trace or a Debugger
A hand trace focuses attention on a few values. A debugger can inspect the program's actual state where a larger calculation becomes surprising.
-
Testing Stable Output Against a Reference File
A reference file records an approved, representative output so accidental formatting or content changes become visible.
-
Testing Sequences of State Transitions
A stateful test exercises several events in order and verifies which effects persist across the events.
-
A Good Test Distinguishes Plausible Wrong Results
Choose an input for which a realistic implementation mistake gives a different result from the promised behavior.
-
Triaging Several Test Failures
Several failures can share a faulty dependency or setup assumption. Find the earliest useful evidence before editing each failing case.
-
Using Synthetic Data in Tests
Synthetic test records keep real personal information out of source files, test output, and review systems.