I'm using Android work manager with a custom initialization. to do that i disable auto-initialization in the manifest like this
<provider
tools:replace="android:authorities"
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.work_manager_init"
android:enabled="false"
android:exported="false" />
And in application code I use this code
private fun initWorkManager() {
WorkManager.initialize(this, Configuration.Builder().run {
setWorkerFactory(appComponent.daggerWorkerFactory())
build()
})
}
And it works fine when I run my application. But when I'm testing with roboletric any class that needs the context by RuntimeEnvironment.application throws this exception
java.lang.IllegalStateException: WorkManager is already initialized.
Did you try to initialize it manually without disabling
WorkManagerInitializer? See WorkManager#initialize(Context,
Configuration) or the class levelJavadoc for more information.
The initWorkManager() get calls and throw this beacuse it doesn't know auto-init is already disabled in the manifest and somehow my test cannot read the values from the manifest file.
Any help or suggestion will be appritiated.