Lesson In Adopting Test Driven Development (TDD)
Tags: testing, bestpractices, python, career
Published: 2019-07-07 16:01:39

---
title: Lesson In Adopting Test Driven Development (TDD)
published: true
description: How I adopted TDD as part of my developer workflow as a developer in a startup.
tags: testing, bestpractices, python, career
canonical_url: https://www.maxongzb.com/lesson-in-adopting-test-driven-development-tdd-read-time-3-mins/
---
![Photo by Louis Reed on Unsplash](https://thepracticaldev.s3.amazonaws.com/i/894xjz3w4yzahghcldy9.jpg)

# Introduction 
Test Driven Development (TDD) has been a part of the developer's term that I view it as an arcane art for me. 

As a **love** or **hate** relationship between the developer who swears by it exclusively to you don't need this attitude. 

Which is similar to adopting Agile software management practices for an organisation.

I found out about it more as I became involved in helping to guide developers in Python for a developer gym organised by Junior Developer Singapore.

Besides trying out tutorials or reading books like  [Clean Code][1], [Python Testing With PyTest][2] & [Test Driven Python][3].

# Benefits of Adopting TDD
Here are the benefits I had gotten while I was helping out in developer gym that helped me in adopting the practice.

As part of my personal developer workflow in the startup, I am currently in.

The benefits I founded are as follows:
* Sanity check -  Allows you to add new features, refactoring or upgrading without doubting yourself
* Reduce debugging time - by spending lesser time to find the error's root cause.
* Instill confidence in your code  - Helps a lot on handing over your code base to another developer. 

Who is maintaining or integrating it to their own besides your documentation

# Lesson Learnt in Adopting
  
## It Works Across Programming Languages
I will save you the religious wars over why x programming language over y programming language is better. 

Despite testing frameworks or libraries differ vastly from each programming language but by knowing TDD.

It could help you transfer your understanding of writing test cases and TDD to another developer even if he/she is using a different language. 

This was something I had learnt while helping to guide developers in one of the sessions of developer gym.

## Speed Up Development Process
I believe that by learning TDD, it helps you to code faster.

Simple when your writing code without test cases, how long do you spend your time in fixing bugs?

Does it take from 5 minutes - 3 hours to fix a bug? Plus you might need to take your time to manually go through your program part by part to figure it out and resolve the bug 

By writing test cases, you know within reason that the error did not occur in a part of your code. 

Instead, with pinpoint accuracy, you find out which code is not performing according to your test cases.

Due to the code that you had introduced earlier.

## Challenges Your Assumptions and Become Self Aware 
In practice by adopting TDD, you become more self-aware of the problem and by **failing** your way towards solving the problem through your test cases.

Since through writing test cases, it allows you to gain **instant feedback** of code you write to solve your problem before writing your actual program in the first place.

This provides you with many test cases you had created to check if the assumption you had in your code is correct while writing your actual code.

Which means the need for you to **constantly** refactor & optimise your test cases to fit the solution you have in mind to solve the problem you are creating to solve.

# Conclusion
Overall learning TDD helped me, to spend much lesser time debugging my code.

Instead, it had forced me to focus on formulating a solution for test cases to gain an understanding and challenging my assumptions to craft better solutions. 

By **failing** my way with a workable solution with the problem I'm given that is reflected in my code.

This allowed me a much better appreciation of TDD and had helped me a lot. 

While guiding developers who are not using my language to work on solving **code katas** in developer gym sessions by Junior Developer Singapore.

If you like my article, please **sign up** for Max [Adventurer's Newsletter](http://eepurl.com/dOUoUb) for awesome content I stumble across weekly in **Python**, **Startup** and **Web Development**.

You can also **follow** me to get the **latest** update of my article on **Dev** 

This post was originally posted on Max's blog at [Lesson In Adopting Test Driven Development (TDD) - Read Time: 3 Mins
](https://www.maxongzb.com/lesson-in-adopting-test-driven-development-tdd-read-time-3-mins/) and [Photo by Louis Reed on Unsplash](https://unsplash.com/photos/pwcKF7L4-no)


# References
* [Junior Developer Singapore][4]
* [Test Driven Python][3]
* [Python Testing With PyTest][2] 
* [Clean Code][1]


[1]: https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882/ref=sr_1_1?keywords=clean+code&qid=1562471652&s=gateway&sr=8-1
[2]: https://www.amazon.com/Python-Testing-pytest-Effective-Scalable/dp/1680502409/ref=sr_1_1?crid=1ACWNXBBZJ9AY&keywords=python+testing+with+pytest&qid=1562471624&s=gateway&sprefix=python+testing+%2Caps%2C422&sr=8-1
[3]: http://www.obeythetestinggoat.com/pages/book.html#toc
[4]: https://www.meetup.com/Junior-Developers-Singapore/