December 2018
Beginner to intermediate
796 pages
19h 54m
English
Unit tests take their name after the fact that they are used to test small units of code. To explain how to write a unit test, let's take a look at a simple snippet:
# data.pydef get_clean_data(source):
data = load_data(source)
cleaned_data = clean_data(data)
return cleaned_data
The get_clean_data function is responsible for getting data from source, cleaning it, and returning it to the caller. How do we test this function?
One way of doing this is to call it and then make sure that load_data was called once with source as its only argument. Then we have to verify that clean_data was called once, with the return value of load_data. And, finally, we would need to make sure that the return value of clean_data is what is ...
Read now
Unlock full access