1

I want to run my unit test cases and integration test cases in different time zone.

sbt test (in gmt) sbt it:test (in gmt)

Is there any way to run them in gmt?

Avenger
  • 793
  • 11
  • 31

2 Answers2

1

I kind of doubt that there is one, universal, reliable way of doing this.

As far as I know, the recommended way would be to assume that computer (server) uses UTC time and you don't rely on the timezone where the computer is at all. You can store settings regarding timezone that is somehow relevant to users, and then you would be able to change than easily by changing the setting that is passed around. (java.time makes distinctions between Local and Zoned units for a reason).

If you want to dynamically change the time that your program sees, well, then you probably have to use something like libfaktime to intercept all calls to system clock. You could probably mix that with Docker to make it easier to run one test with a different time and other with a different time.

I guess in many cases there would be some trick that would let you avoid all of that... but if all we know is that you want to run 2 tests in different timezones without any knowledge about libraries, operating system, etc then it's hard to recommend something better.

Mateusz Kubuszok
  • 24,995
  • 4
  • 42
  • 64
0
$ date
2021-06-25T15:42:23 UTC

$ TZ=Europe/Chisinau date
2021-06-25T18:42:44 EEST

If for whatever reason the application does not respect the TZ variable, you can also use bubblewrap (bwrap --bind / / --bind /usr/share/zoneinfo/Europe/Chisinau /etc/localtime).

Vladimir Panteleev
  • 24,651
  • 6
  • 70
  • 114