4 ms·
Is this really a bad thing? If there's a bug on only one day of the week, then writing your unit test to work on the current day will actually catch that sort o
by lacker 11y ago
Is this really a bad thing? If there's a bug on only one day of the week, then writing your unit test to work on the current day will actually catch that sort of bug. Whereas if you hardcode a day then it will never catch that bug. So it seems there is at least one advantage to this sort of testing in practice.
- breadbox 11y agoUnless the tests are almost never run on the weekends (which is what I assumed the author was implying).
- mason55 11y agoA better way to test it would be to deterministically generate the days that you want to test with. That might be one date for each day of the week, or one date for each day of the year, or some set of dates that include some normal dates and edge cases like leap days. The problem with having non-deterministic tests is that when they break you don't know if it's because the test broke or the code broke and even if it was the code you don't know when it broke. What if someone checked in a change that broke how things were handled on Sundays but the tests were only run on Sundays once/year? You'd have to run each build through the test suite, one by one, and you'd have to do it on that day, just to figure out which check in broke.