No Change-Detector Tests
While listening to “Good Love Dies” by Chance Peña.
See:
- Google Testing Blog: Testing on the Toilet: Change-Detector Tests Considered Harmful
- Google Testing Blog: Introducing “Testing on the Toilet”
What were tests originally for?
Tests are the safety net that protects you when you need to refactor your code, or when another developer adds features (regression).
Tests can also help with the design of your code.
What are Change-Detector Tests?
Tests that act like a checksum rather than actually testing the functionality, which will break in response to any change to the production code, without verifying correct behavior of either the original or modified production code.
Why is it harmful?
Change-detector tests do harm rather than good because:
- the tests do not catch any defects
- the added maintenance cost slows down development (the work loop)
Example (really?)
Wished for a change-detector test:
/// a goddamn good piece of code
fn smallest(nums: &mut [i32]) -> Option<i32> {
nums.sort();
nums.first().copied()
}
#[test]
fn test_smallest() {
let mut nums = [4, 1, 3, 2];
smallest(&mut nums);
assert_eq!(nums, [1, 2, 3, 4]); // look what u made me do
assert_eq!(smallest(&mut nums), Some(1)); // do this instead
}
Some thoughts
I repeat myself quite a lot these days yelling “no change-detector tests!” to my agents (plus no AI slop .md files). I might should put this to my root AGENTS.md, or am I simply enjoying this remained feeling as a pervert for participation?