I have a method calling localtime
that I wrote a unit test for. I seed the call to localtime
in my test so that I know the expected answers. So far, so good. I happen to run the unit test on a machine in a different timezone and, predictably, the tests fail, because they're some # of hours off. I suppose I could dynamically determine the correct expected values but that seems to go against the idea of knowing the answer before asking the question.
Any thoughts on how to approach this? Override localtime
? That seems extreme.
Thanks!
I don't think there's any problem with calculating the values of answers in a unit test. Unit tests should be simple enough to avoid complexity-related bugs, but a simple time zone calculation probably doesn't cross the line.
In this particular case, though, you could set the time zone to a fixed value (or several) as part of the test. See this Stack Overflow post about setting time zone in Perl.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With