3 reasons why you should start creating unit tests as a developer

Unleash the Power of Unit Testing: Ensuring Quality, Confidence, and Client Satisfaction

Bruno Lorenzo
3 min readMay 16, 2023

Writing tests suck.

I’m not going to lie, almost nobody wants to do it. It is not fun and fancy like crafting a brand-new UI. However, it’s one of the most underrated skills that every developer needs to master. You don’t see the benefits of it, I get it, you finished a new feature, why do you have to spend some extra time writing tests? Well, how confident are you that your code will not have problems?

We all hate spending time writing tests at until something happens in production and our client starts losing money because of a bug we didn’t catch on time.

Photo by Fotis Fotopoulos on Unsplash

1. Quality

It’s what we all, as developers, should aim for our code.

Your goal needs to be not only developing your task on time but with high quality. It’s a simple thing, the fewer bugs you have in your code, the better developer you will get.

We want our code has the less amount of bugs. By writing unit tests, you will ensure that the code you wrote, follows the expected behavior you want. Sometimes, you only think of the “happy path” and you leave out of the equation other use cases, there’s no shame in that, we’ve all been there. But if you force yourself to write good tests, consequently you will force yourself to think of many scenarios, not only the base case. Therefore, your code will be more robust, and you will reduce the number of possible bugs.

Writing tests will help you catch bugs earlier and ensure correctness. Plus, as you will need to write tests for different scenarios, you will end up with a well-documented code. Unit test is a tool to improve code quality, take advantage of it.

Don’t only think about getting things done, but get it right.

2. Confidence

Confidence is a must if you’re a developer.

You have to be sure that the work you do is working as you want to. If you will introduce new changes to a live code base or a product already in production, you better be confident in your code.

Unit tests will help you to get that confidence. If you have a good unit test suit up and running, you will have a confirmation that your changes don’t break the things that already work. In addition, since you will be providing test cases for your work, and therefore implicit examples of how the code should work, it will encourage your teammates to review your work. Having unit tests will help in having a better code review process. The better the code reviews are, the better assurance that the changes will work as expected.

Unit tests give us a safety net to catch possible errors in earlier stages. This creates an environment for trying innovative solutions. Build up your confidence and you will be more productive in your work.

Having conviction is a needed soft skill for every developer.

3. Reduce code complexity

Spagueti code is bad.

It’s difficult to maintain and we should avoid it. Oddly enough, unit tests can help to keep our code organized.

While unit tests don’t directly reduce code complexity, they can guide you in the right direction. It will make you think in decomposing your al functionality. By doing this, in the end, you will get a simpler code that will be easier to understand over time. There’s no way to test a 300 lines function. You must break it down.

Making your code testable helps with readability and flexibility. Sometimes you will need to mock some dependencies, which will help in responsibility separation. Therefore, it will push you to follow the best software practices.

Think of unit testing as a way to help you produce better code.

If you’re an iOS dev, let me know if you want an easy how-to guide on how to start creating unit tests in Swift.

Have any questions? Feel free to drop me a message! 🙂

  • 🤓 Join me on Twitter for regular content on iOS development tips and insights
  • 🚀 Check out my GitHub where I share all my example projects

--

--

Bruno Lorenzo
Bruno Lorenzo

Written by Bruno Lorenzo

Software Engineer | Innovation Manager at www.houlak.com | Former iOS Tech Lead | I write about iOS, tech, and producitivy

No responses yet