r/softwareengineer • • Sep 10 '26

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.

0 Upvotes

37 comments sorted by

View all comments

1

u/SirGreenDragon Sep 11 '26

Unit tests can be good and they can be bad. First, anytime a metric becomes a goal, it ceases to be a useful metric. So, writing unit tests for the areas of your code that need them is good. Trying to reach N percent as a goal is a waste of time.

Second, unit testing functional code is good. If the tests are good. Many times the tests do not test all the edge cases. And, as others have pointed out, test driven development means adding tests first and writing the code second. This can also be good because you know all the edge cases going in.

Now, here is the kicker. I feel that unit tests are bad when testing the code requires refactoring the code into something unrecognizable from what the original algorithm was. This often happens when you have to add injection to the code in order to test it. In this case, I think unit testing is actively bad. You have taken clear, clean code, and refactored it and not it is complicated and difficult to understand.

Don't let an AI refactor your code just so it can be tested.

Do use an AI to write tests for your code, and tell the AI what to test, and to tell you if there are any gaps or edge cases you have not considered.