When dealing with dates on android I use jsr310 Android backport by Jake Wharton . This library loads timezone data on app startup using AndroidThreeTen.init(this). Unfortunately this uses context (this = Application) which is not aviable in unit tests.
So just calling some functions that use dates will end in crash: org.threeten.bp.zone.ZoneRulesException: No time-zone data files registered
How to fix that? First thing to do is create resources folder in test path (f.e. project/src/test/resources). Than copy time zone database into that folder. After that I’m using following snippet (in Kotlin) to load database:
just calling this in any test class constructor: