Tests and CI · Chapter 1 of 3 · 3 min

Tests as the First Gate

On a site that is mostly content, the most useful tests check content, wiring and rules, not just functions. Here is the mix, and why speed matters most.

Why tests come first

Every later gate is more expensive. A failing test on a laptop costs seconds. A broken page in production costs visitors and trust. So the test suite is the first, cheapest and most important gate in the pipeline.

Speed is a feature

This site has more than 650 tests and they run in about eight seconds locally. That speed is not a luxury: a test suite that is slow does not get run. If tests take ten minutes, people push without them and let CI find the problem later. Keep the suite fast by:

The five kinds of test that earn their keep

1. Unit tests for logic. Pure functions with clear inputs and outputs: the function that classifies a health check result, the one that works out a seven-day median, the one that trims a page title to fit. These are quick to write and catch regressions instantly.

2. Content tests. On a writing-heavy site, most bugs are in content, not code. Tests here check that every live page has a title and a status, that every internal link points at a page that exists, that a guide has the sections its format requires, and that a draft never appears in the sitemap.

3. Wiring tests. Read the source and check that pieces are connected: a route is mounted, a page is in the menu, a new string has both an English and a Hindi version. These sound trivial and catch the most embarrassing mistakes, like a new page that nothing links to.

4. Route tests. Start the app in the test, make real HTTP requests and check the answers: private pages need a login and are never cached; a payment webhook with a bad signature is refused; a scheduled job without its secret gets a 401.

5. Guard tests. Rules that protect the system from drift: the container must not run as root, the rate limiter must not trust a header any visitor can fake, no file may build a content path by hand. Each one was written after a real mistake, so the mistake cannot come back silently.

Testing failure, not just success

The most valuable tests ask "what happens when this goes wrong?":

Real systems spend a lot of their life partly broken. Test those states on purpose.

What not to test

A test is documentation

A good test name reads like a rule: "private pages are never chosen as health-check targets", "a used payment cannot be replayed after the access expires". Reading the test list is the quickest way to learn what the system promises.

Try it yourself

Pick the last bug you fixed. Write the test that would have caught it, and check that it fails on the old code and passes on the new. That one habit, a test for every fixed bug, builds a suite that matches your real risks.