Why Tests Matter
Scenario: A one-character arithmetic fix silently breaks a different customer path.
New words, in plain English
- Test - code that checks other code behaves as expected
- Regression - a previously working behavior that breaks
- Assertion - a statement that must be true
- Test case - one named behavior and expectation
Tests turn assumptions into repeatable evidence. Good tests are small, deterministic, independent, and describe behavior. Use Arrange-Act-Assert: prepare inputs, call code, verify output.
Analogy: A Python program is like a clear set of instructions for a careful helper: names label things, indentation groups steps, and errors explain where the helper became confused.
A small, real example
def add(a, b): return a + b
def test_adds_negative_number():
result = add(5, -2)
assert result == 3
Tip: Test boundaries and failure paths, not only the happy path.
Goal: Practice this idea in the py-pytest-suite challenge at/labs/python. Fix the broken program, run it yourself, then usecheckto prove the real end state.