The Test Case Dilemma
Software developers love the thrill of seeing code work perfectly! You might even have experienced the rush of code working right the first time.
However, if there is one thing we’ve all learned the hard way it is that code working isolation can (and will) collapse under scrutiny.
That scrutiny can come when test cases enter the picture.
The Setup
It’s happened to so many of us. You craft the perfect solution to a bug, or a feature desperately wanted by customers.
Your logic is flawless and the code works. It gets the job done and all seems solid.
It occurs to you that you need to run tests. You know, just to be sure. You’re not only a great software engineer but you’re a fastidious one too.
You press the button and it instantly lets you know that something is wrong.
Wait, What
Your perfect code is exposed to be flawed. How is that even possible? Your gut takes the pain, and this is a feeling that every developer knows all too well.
The next step is a true test of character. What do you do? Do you dive back into the code to debug, work out what is going on and fix the issues.
Alternatively do you step over to the dark side and just…delete the test case.
Are you able to make the right choice? It’s one that haunts even the most seasoned developers.
You Know What You Should Do
Deleting a test case is a simple and easy way out.
It’s also a dangerous precedent.
If you sweep dirt under the rug it looks clean on the surface but does not deal with the mess long term. If you ignore issues in your codebase you are creating a problem for the future. A deleted test case also deletes the checks that the testcase would provide.
The “right” approach is to embrace failure. It’s a learning opportunity and you should grasp it with both hands. Tests are not there to mock your skills and simply give you warnings — warnings that a good software engineer should heed.
Once you resolve a failing test case you’ll feel even better. You’ll have done a good job and produced code that you know is robust and worth working on in the long term.
Conclusion
You know it makes sense.
You can bring values and integrity to the world of software development. Working as a software engineer is about more than simply writing code that somehow works. It’s about making software that works well, consistently, and under all conditions.
Your future self will thank you if you do a good job today.