Debugging and testing
Write a regression test for a visible bug
By SI100x · Published
A regression test keeps a repaired behavior from quietly breaking again. Begin with the user’s observable problem and choose an assertion that distinguishes the failure from the intended result.
Try this exercise
- Reproduce the bug with the smallest realistic input. Describe the expected result before reading or changing the implementation.
- Write a test that exercises the relevant behavior and fails on the broken version. Avoid asserting only that a particular internal function was called.
- Apply the fix and run the test again. Add a neighboring successful case or boundary case when the change could affect more than the original input.
Check your result
The test should fail for the original problem and pass for the repaired behavior. A test that passes both versions may still be useful, but it is not evidence that it protects this regression.
Explore your next step
Compare course curricula or try a free live demo to ask about prerequisites and practice work.
