Automated testing
Tests that run automatically and catch regressions early.
Automated tests let a team change code with confidence. The useful ones test behavior, not implementation details, and run fast. Test-driven development is one way to make testing part of design rather than an afterthought.
Why it matters for a product engineer
Automated tests let a team change code with confidence, and ship small changes often. The useful ones test behaviour, not implementation details, and run fast enough that people run them all the time. For a product engineer, tests are also a record of what the product promises: what must keep working after every change.
How to do it
- Start each test from a behaviour someone relies on, in the words of the product.
- Test through the public interface of a unit, not its private details, so refactoring does not break the test.
- Cover the edges: empty input, the limit, the wrong type, the failure of a dependency.
- Keep the suite fast. Run it on every change, locally and in CI.
- When you fix a bug, first write the test that fails because of it.
- Delete tests that break on every refactor but have never caught a bug.
Common mistakes
- Tests that repeat the implementation line by line.
- Only the happy path tested, while the bugs live in error handling.
- A slow suite that people skip.
- Tests written after the code, only to reach a coverage number.
Example
Apple’s “goto fail” bug shipped in September 2012 and was fixed in February 2014, 17 months later. One duplicated line skipped the last step of checking a secure connection, so a forged certificate could pass. Mike Bland argues that the block was a clear unit: extracted into a function and tested with one bad input, it would have failed at once.
The lines behind Apple's goto fail bug
if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) 1 goto fail; 2 goto fail; 3if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0)4
- 1A checkJump to the end only if there is an error
- 2Bound to the ifRuns only on an error
- 3The bugAlways runs, with no error set, so the result is success
- 4Never reachedNor the verification after it
The indentation suggests both lines belong to the if. Only a test of the behaviour, with a bad signature, would show the code passing anyway.
ReportedMike Bland, 'Goto fail, Heartbleed, and unit testing culture', martinfowler.com
Sources: The practical test pyramid (Ham Vocke) ↗ · The testing trophy and testing classifications (Kent C. Dodds) ↗ · Goto fail, Heartbleed, and unit testing culture (Mike Bland) ↗
AI leverage
Use AI in your workUse AI to support this skill. Your judgment and verification remain part of the work.
- Workflow
- Generate boundary cases from the specification and ask for behaviors a proposed implementation may have missed.
- Limitations
- Tests generated from the same code can reproduce its assumptions and pass while the product is wrong.
- Verification
- Review expected outcomes against the specification and deliberately break a behavior to see whether the test catches it.
Technical leverage
Place tests at the right boundary, isolate dependencies and protect user-critical behavior with fast feedback.
Evidence of mastery
Put it into practice- Practice
- Protect one risky product behavior with a small, purposeful test suite.
- Artifact
- Tests linked to requirements, including a demonstrated regression they catch.
What good looks like
- Assertions verify outcomes rather than implementation details.
- Failure messages identify the broken contract.
Use this evidence to assess your work. Your map status is a self-assessment, not a certification.
Resources
3- articleStart here
The testing trophy and testing classifications ↗
Kent C. Dodds · 8 minAn argument for leaning on integration tests in product code, where they give the most confidence per test.
- articleGo deeper
The practical test pyramid ↗
Ham Vocke (martinfowler.com) · 2018 · 55 minA thorough, code-heavy guide to unit, integration and end-to-end tests and how many of each to write.
- articleGo deeper
Goto fail, Heartbleed, and unit testing culture ↗
Mike Bland (martinfowler.com) · 2014 · 60 minHow two famous security bugs would have been caught by ordinary unit tests, and how Google built a testing culture.
Tools
1- ToolOpen source