reading-notes

Testing and Modules

Testing

Some important takeaways that I took from TDD is that:

def test_should_return_array_reversed_when_given_array():
    test_array = [1,2,3]
    expected_array=reverseArray(test_array)
    assert expected_array == [3,2,1]

Act: execute the code thats being tested

Assert: assert the expected return value from test function == what you expected it to be.

name == “main


if __name__ == "__main__":

is also known as a ‘main’ gate. It is kind of like a boilerplate code that will help a program only invoke code that it intends to. And keeps us from running imported code.

It is best practice to use a main gate when executing code from a file and getting the code that we expected, to run.

Things I want to know more about

Ways I can implement TDD to my previous code projects

References

In Tests We Trust — TDD with Python

What does the if name == “main”: do?