1. Warning Msg:
- 'instrumentationRegistry' is deprecated. Deprecated in Java
- 'AndroidUnit4' is deprecated. Deprecated in Java
2. solve :
1) build.gradle (module) 파일 >
1.1) testImplementation 'junit:junit:4.12' -> androidTestImplementation 'androidx.test.ext:junit:1.1.0' 대체
1.2) Gradle files have changed since last project sync. A project sync ... Sync Now 클릭
android {
...
defaultConfig {
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
...
}
dependencies {
...
// testImplementation 'junit:junit:4.12' 제거
androidTestImplementation 'androidx.test.ext:junit:1.1.0' // 추가 : junit:junit 대체
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
}
2) ExampleInstrumentedTest.kt >
2.1) InstrumentationRegistry.getTargetContext() -> InstrumentationRegistry.getInstrumentation().targetContext 대체
2.2) import 변경
//import android.support.test.InstrumentationRegistry -> androidx.test.platform.app.InstrumentationRegistry 대체
//import android.support.test.runner.AndroidJUnit4 -> androidx.test.ext.junit.runners.AndroidJUnit4 대체
package com.example.com
//import android.support.test.InstrumentationRegistry // deprecated
//import android.support.test.runner.AndroidJUnit4 // deprecated
import androidx.test.ext.junit.runners.AndroidJUnit4 // 추가 : deprecated 대체
import androidx.test.platform.app.InstrumentationRegistry //추가 : deprecated 대체
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
// val appContext = InstrumentationRegistry.getTargetContext() // 제거
val appContext = InstrumentationRegistry.getInstrumentation().targetContext // 추가 : deprecated 대체
assertEquals("com.example.com", appContext.packageName)
}
}
'안드로이드 > Error' 카테고리의 다른 글
[android][error]bluetooth scancallback (0) | 2020.03.19 |
---|---|
[android][error]webview (0) | 2020.01.20 |
[Android][error] kotlinx.coroutines error (0) | 2019.03.11 |
[android][error]project refresh failed - cache.properties.lock (0) | 2015.11.19 |
[android][error]cannot find symbol variable HttpStatus (0) | 2015.11.17 |