YarikSOffice / lingver

Manage your application locale and language.
https://proandroiddev.com/change-language-programmatically-at-runtime-on-android-5e6bc15c758
MIT License
515 stars 61 forks source link

Doesn't work with Robolectric unit tests #43

Open MuntashirAkon opened 3 years ago

MuntashirAkon commented 3 years ago

You'd get the following error if you use Robolectric for unit testing. The current workaround is to catch IllegalStateException.

java.lang.IllegalStateException: Already initialized
at com.yariksoffice.lingver.Lingver$Companion.init(Lingver.kt:192)
at com.yariksoffice.lingver.Lingver$Companion.init(Lingver.kt:182)
at com.yariksoffice.lingver.Lingver.init(Lingver.kt)

This happens because Robolectric calls Application#onCreate() on each test.

Grch commented 3 years ago

Have you found any workaround? I can't launch unit tests

MuntashirAkon commented 3 years ago

Have you found any workaround? I can't launch unit tests

Create a custom Application test class for Robolectric tests.