DEV Community

Shakil Ahmed
Shakil Ahmed

Posted on • Originally published at shakil.me on

1

Unit testing is more important than you think

Unit testing is more important than you think

The most important benefit unit testing gave me is being able to make changes without fearing things might blow up due to even a small change. The whole process of Software development is dealing with complexity where each new step creates a brand new tangle in the already existing fuck sandwich of a stack.

For smaller projects, you may get away okay without writing unit tests. But in a decent sized project with more than one developer involved, it's a must if you want to keep your sanity intact.

Unit testing is more important than you think

As engineers, all we do is making things that reduce human effort. So why hurt your brain thinking about whether your current changes will break another feature? leave it to the software to test. Unit testing is testing your function as a small unit of your entire app. Besides making sure your function is working properly, this practice has some beneficial side effects as well.

Superior error handling

The difference between a good and bad software is that the former handles errors better. When you write code with tests in mind, you know there will be test cases that provide invalid data or invoke the function with incorrect parameters and expect it to throw certain errors. Having tests in mind will automatically force you to write better code and deal with different types of errors in proper way.

Another way it helps you handle errors better is you can copy test cases for similar features from open source projects. For example, if your code deals with http requests, you can find the test cases commonly used on network requests and add those to your code. Why reinvent the wheel?

Better reasoning about the software

Test driven develoment is overall a better strategy of software development in my opinion. Thinking about your code in this approach gives a clearer picture.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️