Avoiding Future Defects and Documenting Codes
Learn how TDD helps prevent defects and ensures clear code documentation in the development process.
Growing code in development can cause major defects in future productions if proper protection measures are ignored. Let's examine how we can protect our code from future major defects.
Protecting against future defects
As we grow our code by writing tests first, we could always simply delete each test after it has passed. We’ve seen some students do that while teaching them TDD because we hadn’t explained that we shouldn’t do that yet. Regardless, we don’t delete tests once they pass. We keep them all. Tests grow into large regression suites, automatically testing every feature of the code we have built. By frequently running all the tests, we gain safety and confidence in the entire code base.
Adding new features
As team members add features to this code base, keeping all the tests passing shows that nobody has accidentally broken something. It is quite possible in software to add a perfectly innocent change somewhere, only to find that some seemingly unrelated thing has now stopped working. This will be because of the relationship between those two pieces that we previously did not understand.
True agility
The tests have now caused us to learn more about our system and our assumptions. They’ve prevented defects from being written into the code base.
These are both great benefits but the bigger picture is that our team has the confidence to make changes safely and knows they have tests automatically looking after them. This is true agility, the freedom to change. Agility was never about JIRA tickets and sprints. It was always about the ability to move quickly, with confidence, through an ever-changing landscape of requirements. Having tens of thousands of fast-running automated tests is probably the biggest enabling practice we have.
The ability of tests to give team members the confidence to work quickly and effectively is a huge benefit of TDD. We all might have heard the phrase move fast and break things, famous from the early days of Facebook. TDD allows us to move fast and not break things.
Get hands-on with 1400+ tech skills courses.