04.4.1 · Skill in Engineering quality

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.

Your status · Automated testing

Saved in this browser. Sign in to keep it on every device.It colours this skill's tile on your map.

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

  1. Start each test from a behaviour someone relies on, in the words of the product.
  2. Test through the public interface of a unit, not its private details, so refactoring does not break the test.
  3. Cover the edges: empty input, the limit, the wrong type, the failure of a dependency.
  4. Keep the suite fast. Run it on every change, locally and in CI.
  5. When you fix a bug, first write the test that fails because of it.
  6. 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.

Anatomy

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

  1. 1A checkJump to the end only if there is an error
  2. 2Bound to the ifRuns only on an error
  3. 3The bugAlways runs, with no error set, so the result is success
  4. 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 work

Use 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

Tools

1
  • ToolOpen source
    Vitest

    Fast open-source unit and integration test runner for JavaScript and TypeScript.