StoicBuilder

HandbookVIII the PalaestraIntegration tests

VIIIthe Palaestra, Test it

Integration tests

1 min readUpdated 28 November

In plain words

An integration test runs several real parts together, such as an API route, its queries and the actual Postgres schema, to catch the mistakes that only appear where the parts meet.

Where you see it

Every unit test for Harbor's invite flow passes, yet inviting a second teammate fails on staging because a unique constraint on team_members rejects the insert. A test that called the real route against a local test database would have hit the same error on your laptop.

tests/invite.int.test.tsterminal
beforeEach(async () => { await db.execute(sql`truncate teams, team_members cascade`); }); test("inviting a teammate adds a member row", async () => { const team = await createTeam({ name: "Acme", ownerEmail: "owner@example.com" }); const res = await POST(inviteRequest(team.id, "new@example.com")); expect(res.status).toBe(201); expect(await countMembers(team.id)).toBe(2);});
The real route handler against a real, throwaway database. Each test starts from empty tables, so tests can't affect each other.

What goes wrong

  1. Running them against a shared database

    Tests that write to staging leave junk behind and fail when two runs overlap. Give tests their own database, such as Postgres in Docker or the Supabase local stack, and reset it between tests.

  2. Mocking the database everywhere

    SQL that works against a mock can fail in Postgres: a missing column, a constraint, a type mismatch. Keep at least one test per route that talks to a real database with every migration applied.

  3. Testing every detail at this level

    Integration tests take seconds where unit tests take milliseconds. Use them for the seams, such as routes, queries and webhook handlers, and keep detailed logic checks in unit tests.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Add integration tests for Harbor's invite and upgrade routes that call the real route handlers against a local test database with all migrations applied. Reset the tables before each test, never point them at staging or production, and mock only external services like Stripe and email.

Quick check

Sign in to earn +10 XP for it

Unit tests for Harbor's invite flow all pass, but inviting a second teammate fails on staging with a duplicate key error. Which test would have caught it?

Got a prompt that touches integration tests?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.