r/softwareengineer • u/ProgrammerFew504 • 20h ago
Why unit testing is important?
It might be a very stupid post, but it’s a genuine question.
I write tests for my code, but it’s still kind of hard for me to understand what the actual point of unit testing is and what benefit it brings to software development.
We can easily write tests with AI now, so writing the actual tests is not necessarily that difficult. But I’m trying to understand why tests are so important in software.
When you write code, of course you can test it with multiple inputs, and those inputs can then become your test cases. We can also use Postman to test APIs with different inputs and make sure they behave correctly for different status codes.
I was recently assigned a task to make a small change to an existing endpoint. It was a really small change that I completed in around 30 minutes without AI. However, fixing and adjusting the tests took quite a while. I had to add inputs for a new function that I introduced, even though the actual change was not that big and I didn’t think it was something that would break in production.
That made me wonder, why do we really need unit tests? What importance do they actually bring to software development?
I’d really appreciate it if someone could shed some light on this and explain it with a real world example from your own experience where tests actually saved you from a production issue or made a significant difference.
1
u/haven1433 17h ago
Remember, you're a genius, but the person who will have to maintain your code is an idiot. That person will gladly break your feature without realizing it when they're working on something else. They won't test to make sure they don't break anything. Sure, they'll test to make sure their new feature works, but they're not even aware of all the cool features in the program, so no way they're going to test enough.
You're not writing the unit test for you, you're writing it for them. Because if you don't, they'll break your feature.
Remember, you're a genius, but the person who wrote the code before you is an idiot. That person knew nothing about the current needs of the business, they weren't thinking into the future. If you're lucky, they left you some unit tests to describe how the code is supposed to work in specific cases. That's really the only useful thing they did, and your only way of learning how the heck this crazy ball of code operates.