DEV Community

Discussion on: 7 Reasons You Should Be Using Test-Driven Development

Collapse
 
eljayadobe profile image
Eljay-Adobe

TDD puts positive pressure on developers to do several of the SOLID principles as a matter of due course.

The primary key benefit to unit tests for TDD is that they guide the developer to make their code testable. Since the code is testable, and it is unit tested, it can be relied upon to have basic correctness. Which means the code is reliable and robust. And also malleable - it is capable of changing and will squawk if the change breaks something.

A synonym for testable code is decoupled code.

The secondary benefit is the byproduct of TDD: having a body of unit tests that enables refactoring with confidence.

The tertiary benefit is the legacy artifact of having that same body of unit tests that can be run in an automated fashion to catch any regressions of basic correctness.

The secondary and tertiary benefits are insufficient to justify creating unit tests. But the primary benefit is compelling.

Creating unit tests after the fact bypasses the primary key benefit to unit tests.

Also, some languages and IDEs are much more suited to writing unit tests than others. For example, I've used Visual Studio, using C# and NCrunch and NUnit testing framework.

Not only did NCrunch make unit testing a breeze, it also made it... dare I say... fun! Whatever magic pixie dust they put in NCrunch is well worth the price.

I wish I had something like NCrunch for C++. :-(