Mutation testing is a thing. Make minor tweaks to the code under test to validate that the tests fail. If you can flip a 0 to a 1 and the tests don't fail, you likely missed something.
Read up on mutation tests. Frameworks like Stryker.Net will make small changes to your code and check if any unit tests caught and 'killed' that mutation (because the tests now fail when they previously passed) or if the mutation survived undetected (the line was edited and all tests covering that line still passed).
It might have one mutation that changes if (x >= 0) to if (x > 0), another one that changes the same line to if (x <= 0), another one might change if (x == true || y == false) to if (x != true || y == false) or if (x == true && y == false) and so on and so forth...
You want to run the mutation tests and end up with as few mutations surviving as possible.
It can honestly be quite eye-opening just how many mutations can be present in a single line - a line with a long chain of conditional logic can be especially bad for this. I actually intend on running a demo of mutation testing at my work, and in the demo project I prepped I have one line that on its own is going to start out with 15 mutations that Stryker tried and every last one of them survived. This shows that this one line potentially has a lot of complexity to it and it might be a strong candidate to consider for refactoring.
47
u/WisePotato42 12d ago
Me when I was like a month out of college and no one could figure out what work to give me
40
u/sligor 12d ago
Our 40 year old code base is so bloated that we need to test our tests so that we don’t break the tests
9
u/Irish_Puzzle 12d ago
What should a unit-test of a unit-test be testing?
8
u/ChrisWsrn 12d ago
Tests on Unit Tests are typically called Mutation Tests.
3
u/Irish_Puzzle 12d ago
What should a unit-test of a unit-test be testing?
3
u/BobDogGo 12d ago
2
u/theFirstHaruspex 12d ago
This boomer ass meme, how dare you
1
u/OneOldNerd 12d ago
Get out.
1
u/joan_bdm 12d ago
Me when 80% test coverage isn't enough and I write extra code to reach 100%
1
u/hucareshokiesrul 12d ago
It's unit tests all the way down
1
u/a-r-c 12d ago
test my unit lmao
1
u/jewishSpaceMedbeds 12d ago
🤔
But what about testing the tests that test the tests? We need more tests!
1
u/RaymondWalters 12d ago
Unironically did this on one of our test helpers to make sure the helper is helping properly
1
u/apt-maintenance 11d ago
They call me 'The Unit' the way I'm testing their patience
1
u/LittleMlem 10d ago
Quis unit tests ipsos unit tests?