Getting Started with Testing
Explore the fundamentals of unit testing in Python, including defining test boundaries, choosing appropriate testing tools, and comparing unittest and pytest frameworks. Understand how to isolate code for testing without involving external dependencies and improve code quality through effective test design and refactoring techniques.
We'll cover the following...
Testing requires effort. And if we are not careful when deciding what to test, we will never end testing, hence wasting a lot of effort without achieving much.
Defining the boundaries of what to test
We should scope the testing to the boundaries of our code. If we don't, we would have to also test the dependencies (external/third-party libraries or modules) in our code, and then their respective dependencies, and so on in a never-ending journey. It's not our responsibility to test dependencies, so we can assume that these projects have tests of their own. It would be enough just to test that the correct calls to external dependencies are done with the correct parameters (and that might even be an acceptable use of patching), but we ...