How to unit test calling localtime () in Perl?

I have a method that calls localtime, which I wrote for unit test for. I take away the challenge localtimein my test to find out the expected answers. So far, so good. I run unit test on a machine in a different time zone, and, as predicted, the tests fail because they take several hours. I believe that I could dynamically determine the correct expected values, but this seems to contradict the idea of ​​knowing the answer before asking the question.

Any thoughts on how to approach this? Override localtime? It seems extreme.

Thank!

+5
source share
2 answers

, unit test. , , , , , .

, , ( ) . . Perl.

+6

, , - , Test::MockTime Time::Mock, localtime , , .

+5

All Articles