Testing your own work
Before anyone else sees your change, write down the ways it can hurt someone, choose the cheapest test that would catch each, and say plainly which proof will not repeat
You have written the holiday roll-over for scheduled payouts. Every test passes and line coverage of the new module is 94%. What do those results tell you?
Your tests are not a ritual that happens before review. They are the evidence that your change does what you say it does, and you are the only person who knows enough to produce it. A reviewer sees a diff. A QA engineer, where there is one, designs the strategy for a release and explores beyond what you thought of. Neither can test the change as well as its author, because only the author knows which part she is least sure of. The adjacent-role table in this track’s overview puts it this way: QA owns the test strategy and the evidence for release, and you own the tests for your own change.
This chapter is about that smaller job. It follows one change from Ferrowave’s scheduled payouts, the roll-over of a batch from a weekend or public holiday to the next business day, and it teaches the engineer’s version of ideas that the QA track covers at full length. For test strategy, read test strategy and test plans. For the argument about how many tests of each kind to write, read testing philosophies. Here you will learn to write a half-page plan for your own change, to find the seam a test needs, and to be honest about what your evidence is worth.
The model: tests are evidence for four readers
Every test has readers, and a test with none is a cost. There are four.
You, today. You want to know whether the change works before you spend a reviewer’s time. This is the reader most engineers write for, and it is the least demanding.
The reviewer. She wants to believe your change without rerunning your thinking. A pull request with tests that show the awkward cases earns that belief quickly. One with a single happy-path test makes her do your thinking for you.
Whoever is on call. At 02:10 on the 25th somebody reads your tests to learn what the code was meant to do, because the design doc is two clicks away and the tests are in the repository. Names such as rolls_holiday_friday_over_weekend_to_tuesday are documentation.
The next engineer who changes it. In March someone alters the executor, and your tests are the only thing that tells them they broke the roll-over. Evidence that cannot rerun is of no use to this reader, and that point decides much of what follows.
James Bach and Michael Bolton, whose distinction the chapter on exploratory testing develops, separate checking, which confirms a statement you already made, from testing, which is learning something you did not expect. Both belong in your own work. Tables of cases are checks, and you can automate them. Ten minutes of trying to break the thing before you open the pull request is testing, and no suite replaces it.
Start from the ways it can hurt someone
The QA chapter on strategy tells you to start from risk, and that advice survives the move from a release to a single change. Take twenty minutes before you write much code. Write each risk as a failure that someone would notice, then say which test would catch it.
“The scheduler” is not a risk. “A batch due on Saturday still runs on Saturday” is, and so is “a batch due at 00:30 on Saturday in Lagos runs on Saturday because the code looked at the date in UTC”. Write them as sentences with a person in them. If you cannot say who would be hurt, either the risk is not real or you do not yet understand the feature.
Where do the risks come from? Four places, in rough order of yield.
- The change itself. Read your own diff as a stranger. What does it assume about time, about order, about a value that might be empty? What does it call across a network?
- The spec’s silences. A rule that says a batch can be cancelled until 30 minutes before it runs does not say whether that is counted from the date the customer chose or the date the batch rolled to. When you meet a silence, ask the product manager, and write the answer where the next person will find it.
- The people who know. Ask whoever owns the thing you depend on what they would worry about. At Ferrowave that is the engineer in Bank Connectors who keeps the holiday calendar.
- History. Look at the bugs and incidents that touched this area. Defects cluster.
Rank the list. A three-point scale for likelihood and one for impact is enough, as in the strategy chapter, and the numbers are a way to start an argument about order, not a calculation. Then write down what you will not test and why. Silence about a risk looks like a decision nobody made.
Here are the risks for the roll-over, with the cheapest level that could catch each and what that test would need from the world. The ranking in the Artefact below is Adigun’s own.
| Risk, as a failure | Cheapest level | The test needs |
|---|---|---|
| A batch due on a Saturday or a holiday runs on that day | Table of cases on a pure function | A list of holidays passed in |
| A holiday Friday, a weekend and a holiday Monday roll only one step and land on a holiday | Same table | The same list |
| A batch due at 00:30 Lagos time on Saturday rolls on the UTC date and runs on a Saturday | Table on the date function; API test for the wiring | A fixed instant, a time zone |
| The date shown to the customer differs from the date the executor uses | API test | The real scheduler and executor |
| A cancel arrives at 30 minutes before or one second after | API test at the boundary | A clock you can set |
| A batch executed on day 30 is retried and pays twice because its key was made at scheduling and has expired | Integration test with a moved clock | Time that moves 31 days |
The last row is the one to notice. It cannot be tested in real time, because the schedule is 30 days and the key lasts 7. That risk belongs to the design of the feature: breaking down and estimating work puts a key made at execution time in the plan, and the track’s chapter a design doc for one feature takes up the design. Your job here is to say how anyone will ever see that the key works. It also tells you that this codebase will need a controllable clock sooner or later.
What a test needs from the world: the seam
A test fails to get written for a boring reason: the code reads the world directly. It calls the system clock in ten places, and it calls the holiday service over the network. You cannot set the date to 25 December and you cannot add a holiday to somebody else’s service. So the test is skipped, and the skip is rarely a decision.
Michael Feathers calls a place where you can change what the program does without editing the code at that place a seam. A clock that is passed in as an argument is a seam. A calendar client behind an interface is another. Martin Fowler’s note on non-deterministic tests lists time and remote services among the main causes of tests that pass and fail without a change to anything, and the usual cure is the same: put a seam where the world enters. The QA chapter on automation shows clock control in a browser test, and the chapter on data, environments and flaky tests shows why a clock nobody controlled turns up at midnight and month end.
When the seam is missing you have four moves, and they are not equal.
- Make the smallest seam. Pass the date and the holiday list into the function that decides the roll-over. This costs an hour, and it turns most of the risks above into a table of cases that runs in milliseconds. A function that takes its inputs as arguments needs no fake clock at all.
- Build the general seam. A clock and a calendar that every part of the scheduler uses. This is the right long-term answer and, at Ferrowave, costs 1.5 days. It also pays for the 31-day retry test, which nothing else can run.
- Move the world to the clock. If you cannot move the clock to 25 December, move 25 December to today. Ask the calendar’s owner to add a holiday row for today in staging, schedule a batch for later today, and see where it lands. You use the real clock and a faked input.
- Do it by hand and write down what you saw. Fast and weak.
The test of a move is what survives. A table of cases in CI protects the change in March. A staging session proves the wiring today and tells March’s engineer nothing. So any proof that cannot rerun carries a cost, and you pay it with a ticket that has an owner and a date. The first ninety days chapter makes the same point about characterisation tests for old code: what you cannot rerun, you cannot rely on.
A table of cases, in code
For the arithmetic, a table of cases is the best form of documentation. Here is the shape in Python; the language matters less than the layout, and every row has an input, an expected result and a reason.
# Test calendar only. These are fixtures, not the real holiday list.
HOLIDAYS = {date(2026, 12, 25), date(2026, 12, 28), date(2027, 1, 1)}
CASES = [
# scheduled, expected, why
(date(2026, 12, 22), date(2026, 12, 22), "ordinary Tuesday, control"),
(date(2026, 12, 25), date(2026, 12, 29), "holiday Friday, weekend, holiday Monday"),
(date(2026, 12, 26), date(2026, 12, 29), "Saturday, then a holiday Monday"),
(date(2027, 1, 1), date(2027, 1, 4), "holiday on 1 January rolls into the new week"),
(date(2027, 1, 30), date(2027, 2, 1), "Saturday before month end rolls into February"),
]
@pytest.mark.parametrize("scheduled, expected, why", CASES)
def test_roll_to_next_business_day(scheduled, expected, why):
assert next_business_day(scheduled, HOLIDAYS) == expected, why
Two things make this good. The control row shows that the function leaves a normal day alone, which a rule that rolls everything would fail. And the holidays are a fixture in the test, so nobody can break it by editing the real calendar.
Now a rule for your own pull request. A test you have never seen fail may not be able to. Before you push, change the behaviour on purpose, for instance by deleting the holiday check, and run the table. If nothing goes red, the table is not connected to the behaviour. This is a small, hand-made version of mutation testing, which the chapter on testing AI features shows with tools, and it takes two minutes.
Money code needs an invariant, not only examples
Ferrowave pays salaries. When a batch executes, a wrong date moves money late, and a retry that runs twice moves it twice. For a function like the roll-over, examples are enough. For the executor you also want an invariant: a statement that is true after any sequence of events. For a batch, the total of the payouts sent equals the batch total, and each payout is sent once.
Then write the test that tries to break it: run the executor twice on the same batch and count the payouts. The idempotency lesson explains why a retry needs a key or a record, not only a delay, and idempotency and moving money exactly once shows the pattern in a payments system. Testing money and regulated systems in the QA track covers reconciliation tests in full. Your angle is narrower: for the change you made, which invariant could it break, and which test would show that it had?
What goes in the pull request
A reviewer should be able to read your test plan in two minutes. Put it in the description, in this order: what the change must do in three lines, the risks you tested and how, what you did not test and why, and the evidence that will not repeat, with its ticket. The chapter on pull requests that get merged covers the description as a whole. For this chapter, the rule is that a reviewer should never have to ask what you tried.
Name the questions you left open. “The cut-off counts from the rolled date; Senami confirmed on Tuesday” is evidence. “I assumed” is a risk.
Where practitioners disagree
Test first or test after. Kent Beck’s test-driven development writes the failing test before the code, and its defenders say it shapes better design and a steady rhythm. David Heinemeier Hansson argued in 2014 that it distorts design for the sake of testability, and a series of recorded conversations with Beck and Fowler followed, listed in the reading. Fowler’s position there was that self-testing code matters more than the route you take to it. For one engineer, the practical rule is to write the table of cases before the code when the rule is clear, as it is for a roll-over, and after a first spike when you do not yet know the shape.
Mock the dependency or use the real one. Fowler’s Mocks Aren’t Stubs sets out two schools. The classical school uses real objects where it can and checks the resulting state. The mockist school replaces collaborators and checks the calls made to them. Mocks make tests fast and isolated and can tie them to the implementation, so that a refactor breaks tests whose behaviour is unchanged. Real dependencies are slower and more faithful. A reasonable default is to fake the things you cannot control, such as the clock and the calendar, and to use the real objects for the rest.
Staging evidence or production evidence. Some teams hold that a staging test proves little, because staging differs from production, and prefer to ship small behind a flag and watch. The QA track’s testing in production chapter makes the case. For a payout feature, a flag and staging are not rivals. You run the staging check because it is cheap, you ship behind a flag because staging is imperfect, and you watch the first real run.
Day to day
Before you write code, 20 minutes. Write the risk list on paper. Take one question from it to the product manager and one to the owner of whatever you depend on. Treat the time as a rule of thumb: for a change of a day or two, 20 minutes is a fair share.
While you code. Write the table of cases first or alongside, and run it on every save. Commit when it is green, so that a failing step is small.
Before you open the pull request, 10 minutes. Try to break the change: midnight, a repeat, an empty batch, the same request twice. Then do the delete-the-rule check. Write down what you tried, even when nothing broke.
In the pull request. Add the test plan to the description. Mark each piece of evidence as repeatable or one-off, and attach a ticket, an owner and a date to each one-off.
With your reviewer. Ask the reviewer to read the tests before the code. At Ferrowave Oyinkuro does this on Payouts Core: if a case is missing, he says so before reading the implementation, and the implementation then has something to answer.
After the merge. Watch the first real run. For scheduled payouts that means the first batch due on a weekend, and the daily reconciliation file from Reconciliation and Ledger, which compares what was scheduled with what ran.
Every Friday, 30 minutes. Look at the tests you own that failed or were skipped this week. A skipped test with no date is a decision nobody made; give it an owner or delete it. The chapter on flaky tests covers the triage.
There is no QA engineer, and often no staging environment that resembles production, so the engineer is the whole test function. Keep the plan to a half page in the pull request, and spend the time on the risks a customer would notice first: money, dates, and anything that cannot be undone. Fast checks you run yourself carry most of the weight. Write down what you did by hand, because the next hire will not know. The seams you make now cost an afternoon; added after ten customers rely on the code, they cost a week.
A few QA engineers exist and cover several teams, so they cannot test each change; the engineer’s plan is what they read first. Staging is shared and contested, which makes faked inputs and short, tidy sessions the polite way to use it. Agree who owns shared fixtures such as the test holiday calendar, or two teams will overwrite each other’s rows. Expect the first argument about flaky tests and about whose job a red build is. Make the seam work a planned item, not a favour.
A separate quality function, a change advisory process and environment bookings are normal, so your plan becomes an input to somebody else’s gate. Evidence has a format, a retention period and an auditor, and screenshots of a manual run count only if they are dated and attributed. Booked test environments make a staging session a scheduling problem; build the seam so that you need the booking less. Read the release criteria early, and write your plan against them, not against your own idea of done.
Template
# Test plan: <change>
Author · Reviewer · Date · Pull request
## What this change must do (three lines)
## Risks, ranked, each as a failure someone would notice
| # | Failure, and who is hurt | L (1-3) | I (1-3) | Cheapest level | Needs from the world |
|---|---|---|---|---|---|
## Cases
| Risk # | Input (with time zone) | Expected | Why this row |
|---|---|---|---|
## Not testing, and why
| Risk # | Reason | Owner or ticket |
|---|---|---|
## Evidence in this pull request
| Evidence (risk #) | Repeats in CI? | Follow-up: ticket, owner, date |
|---|---|---|
## Tried to break it (10 minutes)
What I did, what I found, and the test I saw fail on purpose.
## Questions for the product owner
Question, answer, date. WORKED EXAMPLE
Adigun, a mid-level engineer in Ferrowave’s Payouts Core, writes the plan for the roll-over of a scheduled batch to the next business day. Oyinkuro reviews it before the code. Senami is the product manager. Dates use a test calendar with holidays on 25 and 28 December 2026 and 1 January 2027; it is not the real list.
Must do. A batch due on a weekend or holiday runs at the same Lagos time on the next business day. The API returns the rolled time. The cancel cut-off counts from the rolled time.
Risks, ranked by L times I.
| # | Failure, and who is hurt | L | I | Cheapest level | Needs |
|---|---|---|---|---|---|
| 1 | A Saturday batch runs on Saturday; payees are paid on a closed bank day | 2 | 3 | Table on a pure function | Holiday list |
| 2 | Holiday Friday, weekend, holiday Monday lands on a holiday | 2 | 3 | Same table | Same list |
| 3 | A batch due 00:30 Lagos on Saturday (23:30 UTC on Friday) runs on Saturday because the code reads the UTC date | 2 | 3 | Table; API test for wiring | A fixed instant and zone |
| 4 | A cancel at the 30-minute boundary is accepted or refused wrongly; a customer pays for a batch it cancelled | 2 | 2 | API test | Handler takes now as an argument |
| 5 | A holiday added after scheduling is ignored | 2 | 2 | Decision first, then a test | Senami’s answer |
| 6 | The date shown to the customer differs from the date the executor uses | 1 | 3 | Staging session | Real wiring, a test holiday row |
| 7 | A batch executed on day 30 is retried and pays twice | 1 | 3 | Integration test, moved clock | Time that moves 31 days |
| Risk # | Input (Lagos time) | Expected | Why |
|---|---|---|---|
| none | Tue 22 Dec 2026 09:00 | Tue 22 Dec 09:00 | control: ordinary day |
| 2 | Fri 25 Dec 2026 09:00 | Tue 29 Dec 09:00 | holiday, weekend, holiday |
| 3 | Sat 9 Jan 2027 00:30 (Fri 23:30 UTC) | Mon 11 Jan 00:30 | UTC date would say Friday |
| 2 | Fri 1 Jan 2027 09:00 | Mon 4 Jan 09:00 | year boundary |
| 1 | Sat 30 Jan 2027 09:00 | Mon 1 Feb 09:00 | Saturday before month end |
| 4 | Cancel Mon 11 Jan 08:29:59, batch rolled from Sat 9 Jan 09:00 | accepted | one second inside the cut-off, counted from the rolled time |
| 4 | Cancel Mon 11 Jan 08:30:00, same batch | 409 | the rule is strictly before 30 minutes |
Not testing. Risk 5 is for Senami to decide; she is told on the pull request. Risk 7 needs a clock that moves 31 days; it goes to the design doc, ticket for Adigun.
Evidence. The table and the cancel cases run in CI (repeat). A staging session with a TEST holiday row for today, added with Juliet in Bank Connectors, checks that the API returns tomorrow’s date and the batch does not run at the original time covers risk 6 (one-off; ticket for a clock seam, Adigun, due before the January payroll run).
Tried to break it. Deleting the holiday check turned two rows red. Senami confirmed the cut-off counts from the rolled time.
Now you
You are the Payouts Core engineer who adds the cancel rule to Ferrowave’s scheduled payouts. The rule, from Senami: a batch can be cancelled until 30 minutes before it runs. The batch under discussion holds 120 payouts of ₦150,000 each, ₦18,000,000 in all, and the customer scheduled it for Saturday 6 February 2027 at 09:00; the roll-over moved it to Monday 8 February at 09:00. Your handler accepts a cancel while the time now is earlier than the run time minus 30 minutes, and otherwise answers 409. The executor moves a batch’s payouts into the send queue at exactly 30 minutes before the run time. Staging uses the real clock and there is no fake clock. Senami has not said whether the 30 minutes count from the Saturday time or the Monday time. A customer asks to cancel on Sunday evening. Write the plan: risks, a table of cases with expected answers under your stated assumption, what you will not test, and the question for Senami.
Self-check
It is Tuesday of the last sprint week at Ferrowave and you are Adigun. The roll-over change is finished: a scheduled batch due on a weekend or holiday runs on the next business day. A table of cases covers the date arithmetic. The wiring has no test (Lagos time, the calendar endpoint, the executor picking the batch up at the new time) because the codebase has no fake clock or calendar, and building them takes 1.5 days. Senami wants the change this sprint, which ends Friday, so the Customer Console team can start on Monday. Juliet in Bank Connectors says staging's calendar reads from a table you may add rows to. The January payroll run is 48 days away.
- POST The Practical Test Pyramid Ham Vocke, 2018
A worked tour of unit, integration, contract and end-to-end tests on a small service. Use it to choose the cheapest level for each risk on your list.
- BOOK Software Engineering at Google, chapter 12: Unit Testing Winters, Manshreck and Wright, 2020
How a large engineering organisation thinks about small tests: what makes them durable and what ties them to implementation. The free web edition is on the authors' site. Read: Chapter 12 on unit tests; chapters 13 and 14 cover test doubles and larger tests.
- POST Eradicating Non-Determinism in Tests Martin Fowler
Names the causes of tests that pass and fail with no change, including time and remote services, and what to do about each. Read it before you add a sleep.
- BOOK Working Effectively with Legacy Code Michael C. Feathers, 2004
The source of the term seam and the most practical guide to making code testable without a rewrite. Read: The chapters on seams and on breaking dependencies.
- POST Mocks Aren't Stubs Martin Fowler, 2007
Sets out the classical and mockist styles of testing, which helps you see why two good engineers disagree about what to fake.
- TALK Is TDD Dead? Kent Beck, David Heinemeier Hansson and Martin Fowler, 2014
Recorded conversations on whether test-first work improves design. Watch one to hear the disagreement from the people who started it.
All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.