Writing

Test names are documentation

10 Sep 2026, 2 min read

If your test names don’t explain themselves, are they really documentation, or just a checkbox?

A good test suite tells a new developer how the code behaves without them reading the implementation. The test names do most of that work. testStreak2() tells you nothing. A sentence tells you the rule.

Name the behavior, not the function

In Launch Control, my daily planner, the streak has one rule that surprises people: if you haven’t completed anything yet today, the streak counts from yesterday, so it doesn’t reset to zero the moment a new day starts.

That rule deserves a test whose name is the rule. Swift Testing makes this easy, because @Test takes a display name:

import Testing

@Suite("Streak calculation")
struct StreakCalculatorTests {
    @Test("Streak counts from yesterday when nothing is completed today")
    func streakCountsFromYesterday() {
        // ...
    }

    @Test("Streak resets after a day with no completed events")
    func streakResetsAfterGap() {
        // ...
    }
}

Read the test navigator and you get a spec:

A pattern that works

For each test I write the name as ”[thing] [does what] when [condition]”:

If I can’t write that sentence, I usually don’t understand the behavior well enough to test it yet.

With XCTest, the same idea works in the method name: test_streak_countsFromYesterday_whenNothingCompletedToday(). It’s longer, but it reads.

Why it matters

Tests that only check a box protect the code today. Tests that explain themselves also protect it from the next person to touch it, and that’s often me.