android Test 용 Context

개배박발불지은만자·2024년 3월 18일

현재 android studio 는 way2 를 기본으로 제공하고 있다.

way1) androidx.arch.core:core-testing:2.2.0

// build.gradle.kts

testImplementation ("androidx.arch.core:core-testing:2.2.0")
// ...AndroidTest.kt
val context = ApplicationProvider.getApplicationContext<Context>()

way2) using InstrumentationRegistry

 defaultConfig {
    ...
    testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    ...
  }
// test.kt
import androidx.test.platform.app.InstrumentationRegistry
    val appContext = InstrumentationRegistry.getInstrumentation().targetContext

0개의 댓글