Unit testing in Python using PyCharm
Create a new project in PyCharm using the plain Python project template. Let’s call it bank_account
. You’ll find the completed example in the source repository for this chapter, but if you’d like to practice creating and testing the necessary code, just follow along.
PyCharm created a file called main.py
. We’ll use it in a moment, but let’s put our bank transaction code in a separate module. One of the tenets of writing good code is writing testable code, and the best way to write testable code is to follow the single-responsibility principle (SRP), where you create units of code that have only one responsibility. SRP is part of a larger set of rules for creating a resilient coding architecture called SOLID, which is an acronym for the following principles:
- Single-responsibility principle (SRP)
- Open-closed principle (OCP)
- Liskov substitution principle (LSP)
- Interface segregation principle...