19 Jul 2022

TDD: software design practice

Short backstory
While working at Launchyard, we were working on the project for already into 6-7 months. Then the company hired the Frank Wiles (Django core contributor) as a consultant  to review the project. And he pointed out that no tests has been written for backend code.  And we literally stopped the development for 1 and 1/2 months, and start writing tests for the already written code.
After this exercise, I realized that  lot of silly mistakes were caught (and fixed) at development stage, instead after deployment. That was a huge boost to me.  Now, I can write code and test it right away, wow that's great !!

Building as a practice
After I have been writing tests all along. There was a company that i joined, nobody was writing any tests. But I said to CTO, I will write tests for this project. And slowly whole team also adopted TDD after seeing the benefits of writing tests.

Sometimes into the job, has to start working on project huge in size (LOC) or with legacy code. It really helps to speed things up.

One time I just joined a company and it was 2nd day And this senior guy came to me and asked "we have to do minor change for this feature., can you check that ?"
I asked "we do not have to tests for this, how do we know if change is working as expected and also not breaking other things. I guess i have to understand this piece of code and then write tests before I can do expected change" .  The guy walked away looking unhappy !!.

One more scenario is that i have found TDD useful is fixing a bug, in right way.


Benefits of TDD:
1. Verify the behavior and correctness of the code.
2. Avoid introducing breaking changes.
3. Support refactoring.
4. Shipping code with confidence and velocity.

I have been part of couple of early stage startups with small teams. And we always started doing TDD, as a practice.  Not as a a optional approach.  Right now TDD is not novelty to have, I see this a necessity of software design practice that team needs to adopt, the sooner the better.

No comments:

Post a Comment