DEV Community

Nithyalakshmi Kamalakkannan
Nithyalakshmi Kamalakkannan

Posted on

Five reasons to buy TDD

TDD - One of the eXtreme Programming practices that entails writing an automated unit test before the code itself!!

If you are a developer, you would have heard about TDD! (If not, I would strongly recommend to get introduced to TDD to get yourself some extra time off your computer! ✌️).

TDD commonly referred as Test Driven Development is not as widely followed as widely it is known!

In this blog, I would like to talk about five reasons why you need to follow TDD.
And there we go,

1. Aides build Quality Product

Quality Product is the dream milestone, every software development cycle pedals to achieve!
Wouldn’t you be excited, if I say TDD helps you to get near that?

When TDD is practiced correctly, you will be able to eliminate as many bugs as possible, thus assured to get a high quality final product!!

TDD advocates for test suits that will cover all possible inputs of the SUT (System Under Test), the common ones, exceptions, edge cases and so on!
And when the system is finally developed, it is expected to work seamlessly for all these use cases... At a big picture, ensuring quality experience of the end user.

2. Tips to Design better

Well, TDD not just drives development...
It's way more powerful design helper!

Test Driven Design [Or] Think Design Develop

It makes you first think on how to design your code. It helps you to understand how the code will be used and how it will interact with other modules paving way to better design decisions and more maintainable code.

It forces you to structure your code properly with modularity. If you aren’t designing your system with loose coupling and proper abstractions... then, TDD is hard to follow! Thus TDD also provides you quick design feedback and suggestions to improve!

3. Safety Nets

One thing that will never change in software development is Requirements change! πŸ˜…

As important as developing a quality product, it is to maintain the quality!!

Your test suits helps you to manage your code changes!
(No no... No Magic!)

When you are following TDD, either you modify the existing code or built on top of the existing one... if all your test suits are green... you can be assured that all functionalities will work as expected!!

4. To refactor like a Pro! 😎

Almost every developer loves refactoring, it's like beautifying your art!! But it becomes a problem only when refactoring results in Production bugs / Sleepless Bug fixes πŸ˜›

TDD helps you to refactor your code confidently!!
Your test suits are there to cry when you break something while refactoring! And hence refactor as much as you want! You can enjoy your sleep without any bugs nightmare... of course, after seeing your all green test suit!!

5. Shortens the feedback cycle

If you are a developer, debugging is something you end up doing pretty much every day! But most of the times, debugging isn't a cake walk... sometimes, they turn to be night mares!!
Figuring out why or where it is breaking, is an interesting yet cumbersome journey!

TDD helps you to shorten this process by giving quick and accurate feedbacks!

You need not deploy your new-code, run a hefty set of manual tests to figure out that there is a bug in your new code!!! Rather just rerunning the related test suits after adding your new code itself will suffice. Your test suits will become red (angry!) when you introduce a πŸ•· !!

The best part is, it highlights what you have broken in which class or module! Hence all you need to do is just make your test suits green (happy!!) and enjoy the extra time you saved!

BONUS

Perfect Documentation

As a nice side-effect, you end up creating well maintained documentation of your code even without any additional steps! Your test suit captures the current code behaviour always!!

With the help of testing frameworks, you can name your tests in plain english explaining what it is testing and what is expected. Even after years (may be decades too!), these tests let anyone interested to understand the code behaviour, to get the grip of its working easily by just going through the test cases!!

That brings us to the end of this blog!

I hope you are now convinced to practice TDD and save some of your development time!
If you are wondering, how to get started with TDD...
Please find the next Blog focused about the same!! πŸ™‚

Happy learning!

Top comments (0)