Useful testing utilities
When it comes to efficiency in writing tests, it usually boils down to handling all those mundane or inconvenient problems like providing realistic data entries, dealing with time-sensitive processing, or working with remote services. Experienced programmers usually boost their effectiveness with the help of a large collection of small tools for dealing with all these small typical problems. Let's take a look at a few of them.
Faking realistic data values
When writing tests based on input-output data samples, we often need to provide values that have some meaning in our application:
- Names of people
- Addresses
- Telephone numbers
- Email addresses
- Identification numbers like tax or social security identifiers
The easiest way around that is to use hardcoded values. We've already done that in the example of our test_send()
function in the Mocks and unittest.mock module section:
def test_send()...