Free Report: Go Away, Bugs!

Keeping Your Code Safe with JUnit, TestNG and Mockito

Download This Report Now:


Keeping your code safe with Unit testing

Unit tests let developers internally control the functionality and compatibility of their applications when they made changes to features, code or the environment.

Believe it or not, unit testing is actually a controversial topic among Java developers. Some think that writing unit tests is a waste of time, while others consider them an essential part of the software development process, and the way to ensure that your new app doesn't, well, suck because it wasn't checked properly. And yet some developers are bored by the topic of unit tests.

Think of This Analogy:

Each time you enter your car and start it up, you take a look at the instrument panel/dashboard, almost automatically. Even older cars are equipped with warning lights, some less serious (like that you need to fill gas), some more serious (like the battery status) and some highly critical (like the engine-is-gonna-explode warning light).

So if you see something wrong, like the "check engine" light is flashing an angry red warning, it probably wouldn't be wise to start driving away. in a similar manner unit tests act as warning signals that something does not work as expected. it wouldn't be wise to deploy code into production when all your unit tests are failing.

But unit tests are just that, early warnings and internal checks that your code does what is expected.

If you really, really know what you are doing, then you might disregard some of them. But this is not the normal case. And like the car analogy, your car without any warning might suddenly stop working (for reasons not detected by the status lights), just like how code that passes all unit tests is not necessarily 100% correct.