Unit tests should always be deterministic / reproducable. It is hard to debug when tests might fail randomly.
- Assign a seed to the RNG
Unit tests should always follow the same execution path, and hit all asserts regardless of the global or local state. This ensures consistent behaviour and that there is no assumptions on whether conditional control flows have been accurately written.
Although it is important that datasets are tested on some level, its more important to test what will be used in production: ORM entities. Assume that there can be inconsistencies in the process of transforming a dataset into the database.
- Representation of a dataset might change, but its less likely that the database entity representation will change
- Datasets might not translate exactly to a database entity, ie. datasets might not have a primary key
- Always have tests for the interface. Tests for helper functions arent as useful unless they are used to generate the data for the interface directly.
- Determine the source of truth and write tests around that
password_hash = generate_password_hash(password='password1')
VS
# the password is `password1`
password_hash = 'a_long_complex_hash_string'