현재 android studio 는 way2 를 기본으로 제공하고 있다.
// build.gradle.kts
testImplementation ("androidx.arch.core:core-testing:2.2.0")
// ...AndroidTest.kt
val context = ApplicationProvider.getApplicationContext<Context>()
defaultConfig {
...
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
...
}
// test.kt
import androidx.test.platform.app.InstrumentationRegistry
val appContext = InstrumentationRegistry.getInstrumentation().targetContext