Am I testing my code or is my code testing me ?

Stanley Ocran
3 min readJun 24, 2022

--

As with any app that you build you want to ensure that it’s working the way you expect and want it to. You want to make sure that the operations and business logic happening with your backend are correct and persist.

Why unit tests ?

Unit tests verify the behavior of your code. In addition to that they ensure that when you update or add new features you can easily test all previous functionality and the new ones. Discovering problems as you code and fixing them is several times better than when you host or put your app into production and then run into those problems. Bugs as they’re popularly known by programmers can be very hard to deal with if you don’t find and fix them fast enough.

Debugging

They often have very costly consequences especially if a business relies on an app that has bugs in it. Bugs can impact performance and fixing them after development can take large amounts of time for huge apps. Remember that one time an app you really needed to use wasn’t working ? Yeah exactly. The correct way to build your apps or at least the recommended correct way to do so should always be

  1. Development
  2. Unit testing
  3. Quality assurance
  4. Production

Unit testing just allows your app to be production ready and increases the time-to-production overall if done well. I’ve adopted this approach in my most recent project which is a Trivia app, so tell me why my app is working as it’s supposed to and my tests are failing! What on God’s green earth is this wayward behavior ?

So much for test driven development. Don’t get me wrong tests are good. They just shouldn’t be annoying me as much as they’re doing now.

Then again it’s my fault for not doing things in a more efficient manner. I could have written the tests first then written the code to pass the tests and repeated that throughout my app. Ah well I’m trying to do everything when some of these tasks are meant to be handled in teams. From what I’ve found online one person would write the tests while another codes to pass them so I guess I shouldn’t be pressed to be good at everything now. On that note, my unit tests can’t fail if I have no unit tests right ?

If the unit test fails, delete that test and move on. Life’s too short for the back and forth.

PS that was a joke please don’t delete your tests or lie to yourself that you’ll fix them later. Also for those in fully fledged teams there’s no such thing as “they” will fix it later. If it’s your job do it and do it well.

--

--

Stanley Ocran

junior web dev, cloud practitioner and all things between.