Neil Macy

Mock Data and Dates

If you're going to use mock data when building your app, for example to mock API responses, make sure that the data you use will stand the test of time.

If you use a date that you expect will always be in the future, and it's only set to be a year or two in the future, it'll come back to bite you in just enough time for you to have completely forgotten about it.

I experienced this in work this week. When the year changed to 2022 a few days ago, we suddenly had tests start failing on us. We had some mock data that was set to 2021-12-31, but our app expected that date to be in the future. And the logic that relied on this was just convoluted enough to obscure the problem (a separate problem but one no less bad). So it took a while to diagnose an issue that should never have come up.

Set your dummy dates well into the future. I changed this one to be 1000 years in the future, which will only be a problem for me if we figure out that Futurama head-in-a-jar technology before I die.

Published on 5 January 2022