We work with large volumes of data, all of them are marked in UTC (in Java). Between reading this data, storing it in a database and retrieving it again, it happened that some of the data was turned off for one hour in the summer. Since UTC has no idea about daylight saving time, this was obviously a software bug. Once this is known, it is easy to fix.
However, it would be nice to have some modulation / integration tests that work regardless of the current time difference - for example. I would like to change the local time zone and repeat some methods over and over in these different time zones to ensure that UTC is processed correctly.
Since the tests should run automatically and - preferably - in one Testsuite, I wonder how best to check the correct behavior. It would be easy to change local settings, such as the time zone, after restarting the JVM, but doing this in a test suite is not so simple.
Does anyone know of a test environment, library, or template that supports this scenario? We usually work with JUnit, but are open to adding another environment / technique if this helps to get rid of such problems. I believe this is integration rather than unit test.
Edit : There are already two very useful answers, but I think there should be more technology there. Does anyone have authoritative information about when / how often TimeZone.getDefault is called (see comments for John Skets's answers)?
Note Even if this question has an accepted answer, I was not completely sure which answer to accept. Even with this agreement, I would like to see more ideas and methods.
Thanks for your input!
java timezone utc
Olaf kock
source share