Add unit tests on a project already in progress

anwar_nairi

Anwar

Posted on January 26, 2019

Add unit tests on a project already in progress

My experience

I am currently in a project and we did not use unit tests. Here we are, one year after, and as the issues were more and more about stuff we were confident with, I felt it was the right time to propose unit tests.

Did you found yourself in my experience? If yes, I give you below my advice to kindly start using unit tests.

One fix = one unit test

Your code base is already big. You do not have the human bandwidth to parse all your methods and create the unit tests.

However, you could start by creating one unit tests for each new issue you fix.

// Fixes issue #31
it('should not allow planning a publishing date in the past', function() {
  // ...
});
Enter fullscreen mode Exit fullscreen mode

Benefits of progressive unit tests

  • they make you more confident when you create your pull requests
  • they forces you to think out of the box by stating what is the expected result of your fix
  • they make you earn some time when you search which edge case you did not thought of if the issue comes back
  • PR reviewers quickly understand which case you are solving

Not convinced yet?

Pavol also wrote about the benefits of unit testing a project in progress in this article. Take a look at it if you need more points of view.

Conclusion

Coding can be frustrating, or even worse, stressing, in a production environement. Deadlines can make us take shortcuts and avoid simple or obvious coding principles, leading to avoidable issues.

I think unit tests are the right tool to help us make our job more enjoyable, by making sure we are building some code on solid basis.

I hope this post made you want to start trying unit testing your code if you did not already!

Photo by Startup Stock Photos from Pexels

💖 💪 🙅 🚩
anwar_nairi
Anwar

Posted on January 26, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related