A failing test is probably right

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the testing category.

Last Updated: 2024-11-23

I was testing a feature to email many advisors. The test results confused me, however, since once one advisor of ten was getting marked as "contacted" in the database (even though 10 emails got sent).

I simply shrugged and changed the test to verify that at least one advisor was contacted, instead of all ten, not wanting to invest more time.

It turned out that I was, in fact, mistakenly only contacting one advisor in the code. (This is because the ORM function being used, sync($advisorId) deleted all existing IDs and replaced with its argument.)

The bigger picture is that I should have gotten the hint when my test failed to work with 2 advisors. I should have held fast and investigated. This also makes me realize how crucially important it is to test for the MANY case in iterative code.

Lesson

Pay serious attention to test failures and do not loosen standards.