Which of the following is more recommended to access Context in instrumented unit tests: using ApplicationProvider or InstrumentationRegistry?
val context: Context = ApplicationProvider.getApplicationContext()
import androidx.test.platform.app.InstrumentationRegistry
val context: Context = InstrumentationRegistry.getInstrumentation().targetContext
I know androidx.test.InstrumentationRegistry is deprecated, but androidx.test.platform.app.InstrumentationRegistry is not.
You can either use
androidx.test.platform.app.InstrumentationRegistryorandroid.support.test.InstrumentationRegistry, according to your respective Android SDK version, and get theContextby: