Home » Software Development » Fools Don’t Write Unit Tests

About Yegor Bugayenko

Yegor Bugayenko
Yegor Bugayenko is an Oracle certified Java architect, CEO of Zerocracy, author of Elegant Objects book series about object-oriented programing, lead architect and founder of Cactoos, Takes, Rultor and Jcabi, and a big fan of test automation.

Fools Don’t Write Unit Tests

“We don’t have time to write unit tests” or “We don’t have the budget for unit testing” are complaints I hear very often. Sometimes it may sound like, “We don’t use TDD, so that’s why there are no unit tests,” or even “TDD is too expensive for us now.” I’m sure you’ve heard this or even said it yourself. It doesn’t make any sense to me. I don’t get the logic. In my understanding, unit testing is not a product; it’s a tool. You use tests to develop a product faster and better. How can you say you don’t have time to use the tool that makes your work faster? Let me show you how.

TDD or not, a unit test is a unit test. Either you create it before the main piece of code or after it.

A unit test is a tool that helps you, a developer of software, “run” your stuff and see how it works. How else can you check if it works? When I hear, “I don’t have time for unit tests,” my next question is: “How did you test your code?”

I seriously can’t understand how it is possible to write something and then not test it. Well, unless you’re paid monthly and nobody really cares about your deliverables. If you do care about the software you produce, you’re interested in seeing it in action, right?

So, how do you do this?

If it’s a one-page PHP website, you can probably run it locally on Apache, modify it on disk, and then Cmd+R many times. That’ll work for a primitive piece of code and only for you, a single developer of it. But I hear this “I don’t have time” argument from programmers working on enterprise systems. How do you guys test your code?

I would compare unit tests with OOP classes. You can design the entire application in a single class with a few thousand methods. You will save time on creating other classes, structuring them, thinking about connections between them, etc. It will be a single 20,000-line .java file. And you’ll say that “you didn’t have time to create classes,” right? What would we say about such a product and the author of it? Right, we’d say he or she is just stupid. And it has nothing to do with time or budget. Such a programmer just doesn’t know how to use object-oriented programming tools, like encapsulation, inheritance, polymorphism, interfaces, method overloading, etc. It’s not about time or budget; it’s about skills and discipline.

The same is true for unit tests. If you create code without unit tests, it may work, just like that monster class with 20,000 lines, but the quality of your product will be very low. And not because you didn’t have time to write unit tests, but because you didn’t know how to do it.

So every time I hear, “I didn’t have time for unit testing,” I understand that you just didn’t know how and are trying to conceal that fact behind false excuses. It’s not professional, to say the least.

Reference: Fools Don’t Write Unit Tests from our JCG partner Yegor Bugayenko at the About Programming blog.
(0 rating, 0 votes)
You need to be a registered member to rate this.
1 Comment Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Oleksandr Mandryk
4 years ago

Yegor, of course you are right, but one important thing is that unit tests must be correct and actual.