更推荐Context
在仪器化单元测试中访问以下哪项:使用ApplicationProvider
或InstrumentationRegistry
?
val context: Context = ApplicationProvider.getApplicationContext()
import androidx.test.platform.app.InstrumentationRegistry
val context: Context = InstrumentationRegistry.getInstrumentation().targetContext
我知道androidx.test.InstrumentationRegistry
已弃用,但androidx.test.platform.app.InstrumentationRegistry
不是。