Published on: 27.11.2019
From my point of view, unit tests are useful, especially for refactoring functions that have clearly defined inputs and outputs.
One thing that is impossible to test is anything regarding time/date code because whenever you run it is a different time 🙂 .
For example, if you have a function that calculates the number of days between two dates, the only way to test is to somehow mock current time/date.
in Python, there is FreezeGun.
def test_wrong_dates_one(test_input, expected_output):
assert calculate_date(test_input) == expected_output
It is implemented as a decorator, which is handy and readable in code.
So far I have not found any problem with FreezeGun.