Testing against today's date



Suppose there is an automated test case for a report:

  1. Generate a report for today
  2. Check if the date printed on the report is today’s date

The question is: how can this test case fail?

The obvious answers may include:

Let’s focus on the last situation. What does it mean if the date is incorrect? The answer is not always “there is a product bug that prints an incorrect date on the report”. It can also mean that there is a test issue… Below an example of execution (with timestamps) that triggers a test bug:

  1. Generate a report for today
  2. Check if the date printed on the report is today’s date

The report was generated on May 1st but the date check against “today”’s date happened on May 2nd. The test fails though the report is correct => test bug.

How do you mitigate this?

PS: That’s a test case that I wrote for one of the features in AX2012. It has been executed almost daily and it failed, for the first time, after 3 months.