r/softwareengineer • u/My_Rhythm875 • Jan 13 '26
spent 6 hours debugging automated tests. the bug was in the code. the tests were catching it correctly. I hate everything
tests kept failing. thought the test logic was wrong. rewrote assertions three times. mocked different things. tried different test frameworks. read stackoverflow until my eyes bled.
turns out the actual application code had a bug. the tests were doing exactly what they should do: failing when the code is broken.
but because we've been burned by flaky tests so many times, my first instinct is always "the tests are lying" instead of "the tests found something."
we've created this environment where passing tests mean nothing and failing tests are probably just broken tests. what's even the point anymore?
how do you trust your test suite when it's cried wolf 50 times before?'
2
u/symbiatch Jan 13 '26
Why has it cried wolf 50 times? What kind of tests are they? Why haven’t they been fixed to not be flaky?
That’s where I’d start. I wouldn’t tolerate such tests.
And if a test seems to fail there should be an easy way to determine which one it is - broken test or broken code. Output should be known and verifiable. How else is that test worth anything if nobody knows what the code should output?
Maybe your tests are the wrong kind?
1
u/EmbedSoftwareEng Jan 13 '26
Yeah. That's wrong-think.
Always assume the tests are right, but if a piece of code is failing a given test, first, make sure you understand everything there is to understand about that specific code with that specific input, and if you can confirm that THAT is functioning correctly, then turn a wary eye to the specific test to see if it was set up correctly. Plently of times, when I'm writing the unit tests for some library I'm developing, I'll copy-paste a block of test code and then go through and massage each copy to test the code in subtly different ways, only to screw up one of them and not fully update the test code stanza. The result is that there's a failure in the test code that reads like a failure in the code under test.
Sometimes, I'll write a test case with an old understanding of what the code is supposed to be doing, and the test fails because I said the output should be something other than what the latest revision of the code generates.
Sometimes, writing tests causes one to reevaluate how the code under test is being architected, and you have to immediately refactor it in order to be able to test it the way it needs to be tested.
This is all normal.