Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robolectric RuntimeEnvironment.application is deprecated, where is ApplicationProvider.getApplicationContext()?

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!

like image 544
Charles Madere Avatar asked Oct 18 '18 23:10

Charles Madere


People also ask

Is Robolectric deprecated?

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.


1 Answers

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

like image 155
dudi Avatar answered Sep 19 '22 20:09

dudi