A passing test suite can check nothing
Passing is not the same as checking
You ask an AI coding assistant for a feature. It writes the code. It writes the tests. It runs them and tells you everything passes.
That report is true, and it tells you less than it seems to. A test passes when it does not fail. Nothing in a green result says the test would have failed if the code were wrong. A test that never fails proves nothing.
If you cannot easily read the code yourself, you have no way to tell the two cases apart by looking at the green result. Here is an example of the problem.
A test that runs the code and checks almost nothing
This function prices a delivery. An order over 20 kg adds a 15 dollar surcharge. An express order costs double.
def shipping(weight_kg, express):
if weight_kg <= 0:
raise ValueError("weight must be positive")
cost = 5 + weight_kg * 2
if weight_kg > 20:
cost = cost + 15
if express:
cost = cost * 2
return cost
Here are three tests for it. All three pass.
import unittest
from cart.pricing import shipping
class ShippingTests(unittest.TestCase):
def test_heavy_express_order(self):
result = shipping(25, True)
self.assertIsNotNone(result)
def test_zero_weight_is_rejected(self):
with self.assertRaises(ValueError):
shipping(0, False)
def test_light_standard_order(self):
self.assertEqual(shipping(10, False), 25)
The second and third tests are real checks. The first one is not. It calls the function with an express order of 25 kg and asserts only that something came back. The surcharge line and the express line both run, so a coverage report would count them as covered.
Now change the surcharge line to cost = cost - 15. The function still returns a number. All three tests still pass. Change the express line to cost = cost / 2. Same result. The suite stays green while the prices are wrong.
Breaking the line shows it
There is a direct way to find out whether a test would notice a mistake: make the mistake. Change the line to something wrong, run the tests, and see whether any of them fail.
- If a test fails, a test noticed. The line is checked.
- If every test still passes, nothing noticed. The line is unchecked.
Doing this by hand means one edit and one test run for every line of a change. RedMachine does it for you. It takes each line you changed in a git change, breaks it on purpose, one line at a time, and runs your tests each time. It then writes a receipt whose chain you can check later. There is no AI model inside it, and it does not write tests for you. The technique is called mutation testing, and this post explains it in plain words.
The function is in cart/pricing.py, starting on line 1. With these three tests, RedMachine reports this (excerpt):
KILLED cart/pricing.py:5 [> to <]
SURVIVED cart/pricing.py:6 [+ to -] every test passed with this line broken
line: cost = cost + 15
broken as: cost = cost - 15
KILLED cart/pricing.py:7 [condition negated]
SURVIVED cart/pricing.py:8 [* to /] every test passed with this line broken
line: cost = cost * 2
broken as: cost = cost / 2
counted 8: killed 6, survived 2, unviable 0, not tried 0
RESULT: FAIL. 2 changed lines are not proven by any test.
KILLED means a test failed when the line was broken. SURVIVED means every test still passed. Here, no test checked the surcharge or the express price. The three tests all passed before RedMachine ran, and two of the changed lines were still unchecked.
After a test was written for each of those two lines, the same command reported that all 8 counted lines were killed and the result was PASS.
Why reading the tests does not settle it
A weak test often looks reasonable. Its name says what it is for. It calls the right function. It has an assertion. You have to ask what that assertion would catch, and for each line, to see the gap. Breaking the line asks that question directly, and the answer is a test failing or not failing.
The question is also the one that matters when an assistant did the work. The assistant wrote the code and the tests together, then judged them itself. A separate check that does not share its opinion is worth having.
What a pass does and does not mean
When RedMachine says PASS, it means that no counted line survived: every line it could break and still build was KILLED, and none was left untried. Lines no break could build (UNVIABLE) and lines a person waived do not fail the run; they are listed, and the RESULT line counts them. That is all it means.
- It does not mean the code is right. A line a test proves can still be wrong in a way the test agrees with.
- It does not make a test a good test. One failing test is enough to prove a line.
- It tries one break per line by default, so a proven line may still hide another wrong version that no test notices.
- It does not find bugs and it does not write the missing tests.
What it does give you is a list of changed lines that no test would catch if they were wrong, and the broken version of each one. That list is a concrete thing to hand back to the assistant. The post on using it with a coding assistant shows how that loop works. The questions page covers the rest.