I changed one number and it took seven files: the tests were holding copies
I raised a default timeout. The production change was one line:
pub const BRING_UP_DEFAULT_DEADLINE: Duration = Duration::from_secs(21600);
The commit that shipped it touched seven files and changed fifteen lines. One line was the constant. Four were documentation. The other ten were tests that each held their own hardcoded copy of the old value and had to be rewritten to match.
That ratio is the whole story. When a one-line change to a default drags ten lines of test churn behind it, the tests weren’t testing the default — they were restating it.
What I actually wrote
There were two shapes of mistake, and I made both repeatedly.
Shape 1: asserting a constant equals a literal copy of itself
assert_eq!(bring_up_deadline(root, &sink), BRING_UP_DEFAULT_DEADLINE);
assert_eq!(BRING_UP_DEFAULT_DEADLINE, Duration::from_secs(21600));
The first line is a real test: it checks that the function returns the default when nothing is declared. The second line checks nothing about behaviour at all. It reads a pub const and compares it to the number it was declared with. The compiler already guarantees that.
This assertion has exactly two possible outcomes. Either it passes, having verified a tautology, or someone deliberately changes the constant and it fails — demanding that the same edit be made a second time, in a second place, for no reason. There is no third outcome where it catches a bug. Its only effect on the project is to add a file to every commit that moves the value.
Worse, in one case I had this assertion inside a for loop over two fixtures, so a compile-time constant got compared against the same literal twice per run.
Elsewhere I had written an entire test that was nothing but this pattern:
#[test]
fn the_render_is_bounded_by_the_scaffolds_own_deadline_and_the_bring_up_by_the_default() {
assert_eq!(SCAFFOLD_DEADLINE, Duration::from_secs(1800));
assert_eq!(BRING_UP_DEFAULT_DEADLINE, Duration::from_secs(21600));
}
The name makes a claim about behaviour — that a render is bounded by one deadline and a bring-up by another. The body never renders anything, never brings anything up, and never observes a deadline being applied to anything. It reads two constants. Meanwhile, the genuine test of that exact claim already existed a few dozen lines below in the same file: it runs the operation and checks the output. My constant-comparison test added nothing to it except maintenance.
Shape 2: retyping the number into an expected message
The production code builds its user-facing message with format!, sourcing the number from the constant:
let default = BRING_UP_DEFAULT_DEADLINE.as_secs();
format!("The bring-up is bounded by {default} seconds, the default.")
And then in five separate places across four files, I asserted against that message by typing the whole sentence out by hand with the number baked in:
assert_eq!(
*said.lock().expect("unpoisoned"),
vec!["The bring-up is bounded by 21600 seconds, the default."]
);
So the number now lives a second time inside a string literal — harder to find by search, and with the test’s actual intent (that the message names the default) buried in prose.
One of these was worse still. It asserted a full sentence that hardcoded four things the production code sources from named items: the config file path, the config key, the default value, and the parser’s own error text. Any of those four changing breaks the test without any change in behaviour.
And the most embarrassing one:
&& line.ends_with("the bring-up is bounded by 21600 seconds, the default.")),
This test was already composing its match structurally — starts_with a prefix, contains the interesting value, ends_with a suffix. I chose that structure specifically to avoid depending on the exact full text. And then I typed the number into the suffix anyway, reintroducing the dependency I had gone out of my way to avoid.
While I was in there I noticed that same test’s name says “declares no deadline” while its body supplies a malformed declaration. The name and the body disagree. That’s a separate defect, but it comes from the same carelessness.
Why it’s wrong, concretely
The tests asserted the implementation instead of the requirement. The requirement is: a checkout declaring no deadline is bounded by the default, and the output names the number of seconds it was bounded by. Neither of those requirements mentions 21600. The test should check that the returned deadline is the default and that the message names the default’s value. None of my tests needed the literal number. All of them had it.
grep saved me, and it won’t always. The commit did find all seven copies — because grep 7200 happened to catch every one of them. If I had expressed the value in a different unit somewhere (2 * 60 * 60), or spelled it in prose in another form (“two hours”), the search would have missed it and the suite would have failed on the next run for a reason unrelated to any bug. Relying on a successful grep is not a maintenance strategy.
I duplicated the format string, not just the value. The production format! call is the single definition of that sentence. My tests re-defined it five times. A pure wording change — “is bounded by” to “runs for at most” — is a documentation-level edit that would now break five tests across four files, with no behaviour change whatsoever. I built a tripwire across the path of every future copy edit.
What I should have written
Delete the tautological assertion. The line above it already does the work:
assert_eq!(bring_up_deadline(root, &sink), BRING_UP_DEFAULT_DEADLINE);
Delete the test that contains only constant comparisons. The behaviour it names is already covered by the real lifecycle tests sitting beside it.
Derive the expected message from the same constant the code derives it from:
let default = BRING_UP_DEFAULT_DEADLINE.as_secs();
assert_eq!(
*said.lock().expect("unpoisoned"),
vec![format!("The bring-up is bounded by {default} seconds, the default.")]
);
Or, where the test only needs to know that the default was named and not the exact prose, match on the parts:
.any(|line| line.contains(&format!("{default} seconds")) && line.ends_with("the default."))
Either form makes the next change to the constant a one-line commit, which is what this one should have been.
What I’m changing in how I work
assert_eq!(SOME_CONST, literal) is a code smell with no legitimate use in my code. If the assertion’s only input is a compile-time constant, the compiler has already made the guarantee. I’m treating any such line as something to delete on sight.
A test whose body touches no behaviour should not exist. If I can’t point at the function call that exercises the thing the test name claims, the test is a decoration. The test name is a promise; the body has to keep it.
Expected strings get built from the same named items the production code builds them from. If production says format!("... {default} ..."), the test says format!("... {default} ...") too, importing the same constant. The sentence has one definition.
Test churn is my review signal. From now on, when I change a constant and find myself editing tests to match, I stop and ask whether those tests should have needed changing. If the answer is no, the fix isn’t to update them — it’s to remove the copy. A one-line production change that produces a seven-file diff is telling me something, and I should listen to it before committing rather than after.
Prefer structural assertions, and then actually commit to them. I had already reached for starts_with/contains/ends_with in one place, which means I knew the right instinct. The failure was going halfway and then hardcoding the value into the “structural” part anyway. Picking the robust tool doesn’t help if I undermine it on the next line.
The underlying habit I need to break is treating tests as a place to write down what the code currently says rather than what it’s required to do. A test that mirrors the implementation can only ever tell me the implementation changed — which I already knew, because I changed it.