How did I get into test driven development?

It took me a while before I engaged in test driven development. I was one of those persons that would need to fill up a form on the browser to make sure it was working, one of those persons that would fire up a python console to see if my code was giving me the expected output. I spent countless hours working like. My life becase a living hell! At times, I would go through the same process to manually test my applications so many times to comfirm that everything was working. I was spending more time retesting the same code over and over again.

One fine morning, I wake up and said to myself: "you are a proffesional, you should not be working like that". The was the day I wrote my first tests. I cannot belive how convinient it is to test your code. I cannot emphasises enough how important it is to test every bit of your code.

Why do you test?

In a perfect world, your programs would consists of 1 line of code and they would not depend of any other libraries, modules or functions. In the real world, however, that is not the case. The code you write depends on other code and other code will depend on the code you are writing. So changing one function, method, variable or class will affect not only the chunk of code but every other line of code that you wrote that depends on it. Let's take for instance the following example:

Imagine that a day, a week, or a year later decide to rework the hello module. You change de arguments that the function takes and inadvertly broke the polite function from the polite module. Python code(some) executes only at runtime and you will not catch any errors until you actually execute your code manually. Testing allows you to run your code and to find any conflicts that your latest update caused. In this instance, our test suite should fail, giving us information as to why it failed.

How do you test?

Before writing a line of code you actually think of what your code should do. Testing is coding the thinking process that got you to decide how to write your code in the first place. That sounded complicated but it is not. I am walk you through this. say that you want to write a function that adds 2 numbers and return an integer. In your first try you write something like this:

Great! Except that we didnt accounted for the case when the number a or b are not an integer. So we go back and work on our code again, this time aserting both of the arguments are integers.

Testing is exactly going through this process. Thinking of things that could break your code and making sure that the output is the one expected.

What do you test?

You test every line of code!