Skip to content
build-3000
testing

Testing Your App

Executable proof that your app behaves - unit tests, integration tests and calm failure reading.

Before this: Authorization and Roles

Objective

Build an automated safety net around critical behavior, direct agents to write meaningful tests, review them skeptically, and treat a red suite as the emergency it is.

Vocabulary

The words to use when directing your agent.

unit test
Checks one small piece of logic in isolation - a function with known inputs and outputs.
integration test
Checks pieces working TOGETHER - a request traveling through auth, guards and store.
assertion
The statement inside a test that must be true - the actual check.
fixture
Reusable known test data so tests start from predictable states.
flaky test
A test that passes and fails without code changes - trust erosion incarnate.

Understand it

Arrange, act, assert

Every test reads the same: ARRANGE known state (seeded user, two expenses), ACT once (call the function or endpoint), ASSERT the outcome (total equals X). Deviation from this rhythm is usually a test trying to do too much.

The mutation experiment

Want to know if tests actually bite? Break the code ON PURPOSE - flip a comparison sign - and rerun. Suite stays green? Your tests decorate, they do not defend. Fix the tests, revert the sabotage, keep the lesson.

Core concepts

Tests are executable DoD

Your Definition of Done lists behaviors; tests PROVE them on every run. Manual verification decays and gets skipped; suites execute identically forever. The best DoD items convert into test names almost word for word.

Meaningful beats exhaustive

Ten tests covering money math edge cases, permission denials and the auth journey outweigh two hundred trivial assertions. Test what BREAKS matters: totals rounding wrong, guards leaking, sessions surviving logout.

Examples

A unit test worth keeping

calculateTotal([100.10, 200.20, 300.30]) asserts exactly 600.60 - catching float-rounding bugs that manual testing routinely misses. Money math is unit-test heaven: tiny, pure, catastrophic when wrong.

An integration test worth keeping

Register, login as user A, attempt to delete user B's expense, assert 403 AND that B's expense still exists. One test, three layers, the exact promise of Level 2 proven executable.

Common mistakes

Common mistake

Chasing coverage percentages with hollow tests that assert nothing meaningful.

Fix

Cover critical BEHAVIORS; ignore the percentage. Coverage reports measure execution, not protection.

Common mistake

Leaving failing tests red while continuing development.

Fix

Red suite means STOP: fix or explicitly disable-with-issue. A red suite everyone ignores is worse than no suite.

Working with your AI agent

Flip the delegation: ask your agent to WRITE TESTS FIRST from your DoD list, watch them fail, THEN implement until green. Reviewing test names against the DoD is the fastest spec-review you will ever do - and gaps show up as missing tests, not missing features discovered in production.

Build it

The module’s real project. Your agent builds; you direct and inspect.

Project: Safety Net

Wrap the Private Ledger in genuine automated protection: unit tests on money math and validation, integration tests on the auth journey and cross-user isolation - then prove the net catches falls with a deliberate sabotage experiment.

Requirements

  • Unit tests cover total calculation (including float-rounding cases) and every validation rule
  • Integration tests cover the full auth journey and the cross-user isolation matrix
  • Suite runs green with ONE documented command
  • Every test name states the BEHAVIOR being proven, readable as sentences
  • Mutation experiment performed and documented: sabotage a comparison, suite went red, reverted

Context for your agent

Write a test suite for my Private Ledger BEFORE touching implementation details: unit tests for total math (include tricky decimal cases) and each validation rule; integration tests for register-login-access-logout and the two-user isolation matrix including deny assertions. Tests-first: show me failing tests derived from my DoD, then make them pass against my existing code - where they already pass, verify they are actually asserting (not vacuous). One command must run everything.

Verify it - twice

Check every item yourself first. Then hand your agent the prompt and compare verdicts.

Self-verified0/8
Functional
Architecture
Testing
Production

Verification prompt - paste into your AI agent

Assess my Safety Net suite as a skeptical QA lead. Verify PASS or FAIL with evidence: (1) eight-plus tests exist and names read as behavior statements, (2) money math includes a genuine float-rounding edge case, (3) deny paths assert specific status codes, (4) fixtures prevent setup duplication, (5) one-command execution works as documented. Then perform your OWN mutation test - sabotage something I did not - report whether the suite caught it, and identify the least valuable test in the suite with reasoning.

Run this against “Testing Your App” after your own checklist pass. Where the agent and you disagree, investigate before moving on.

Review questions

Answer out loud. If you cannot, revisit before moving on.

  1. Convert three DoD items from your last project into test names.

  2. Why is a flaky test more dangerous than no test at all?

  3. What did the mutation experiment teach you about YOUR suite specifically?

You can now

  • Delegate tests-first development and review them meaningfully
  • Protect critical behavior with executable proofs
  • Keep suites green, fast and trustworthy over time

Up next

Ship: Team Task Manager