I switched to Robolectric 4.0 Beta 1 from 3.8 because I need compatibility with Android 9 (API 28).
With this change, RuntimeEnvironment.application
is now deprecated.
The replacement is apparently to use:
androidx.test.core.app.ApplicationProvider.getApplicationContext()
I have no idea where exactly this code is. It must be within a separate dependency entirely. Where is it? How do I add it to my project?
Thank you!
Robolectric is intended to be fully compatible with Android's official testing libraries since version 4.0. As such we encourage you to try these new APIs and provide feedback. At some point the Robolectric equivalents will be deprecated and removed.
As described in the Robolectric Migration Guide to 4.0 you have to add the androidx test core dependencies testImplementation 'androidx.test:core:1.0.0'
to your build.gradle
After this you can use the ApplicationProvider.getApplicationContext()
method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With