testingautomated-testsmathics

Year-dependent test


What is the best practice for automatically testing the correct behavior of a function that depends on the current year? Specifically, I would like to add a test to the function DateList in Mathics (a Mathematica-like CAS) that ensures that the current year is returned when no year is given as an argument.

Two possible solutions come to my mind:

  1. Hard-code the current year in the test. So this test has to be updated every year with the potential of some failing integration tests after New Year.
  2. Create another function that is supposed to return the current year and ensure they return the same. This reduces the probability of errors but, of course, still both functions could be wrong.

Any other ideas or pointers to existing practice?


Solution

  • I use the time on the server to get the current Date/Year and unit-test my unit that it returns the same year (which I got from the System Time)

    You should keep in mind the TimeZone difference when testing the returned value against the current Server DateTime.

    This works for my testing, and hope it helps you too.