Member-only story
Python
8 Levels of Using unittest in Python
From basic usages to advanced tricks
How to test a machine?
Simple, just turn it on and check if it works.
But if it doesn’t work, how can we know which part causes the issue?
We probably need to test every single component of the machine to dig it out.
In the software industry, this is called unit testing.
Unit testing is a software testing approach where individual components or modules (units) of an application are tested in isolation to ensure they work as intended.
As to Python, there is a built-in module — unittest
— which provides functionalities for a majority of testing scenarios that every Python developer may encounter.
But since writing tests is different from writing other programs, you may feel confused about the usage of the unittest
module under complicated testing scenarios.
This article is here to rescue you. It explains how to leverage the power of the unittest
module to make your code robust and bug-free, through 8 progressive levels from basic to advanced.