Introduction to Unit Testing
Explore the fundamentals of unit testing applied to machine learning pipelines. This lesson helps you understand what unit testing is, why it is essential for catching bugs early, and how it improves code quality and maintainability. Learn the process of testing individual components and the principles of test-driven development to build robust ML code.
We'll cover the following...
Now that we have a working pipeline ready, it’s time to reflect on our development journey. We started off with the architecture of the system and decided on the directory structure and code organization. Then we designed and developed the individual components that make up our ml_pipeline library and the top-level pipeline.py code. We trained the iris classifier model successfully using the pipeline. Finally, we extended the pipeline for the AutoMPG regressor. So is there anything left to do? Actually, we’ve left out a major developmental activity, which is the writing and running of unit tests.
What is unit testing?
Unit testing is the process by which individual units of source code are tested. What is an individual unit? In our case, each class method is a unit that needs to be tested separately. For each unit, the process is as follows:
Set up the test: In the case of class methods, we would instantiate the class with the appropriate parameters.
Run the test: ...