歡迎大家,我請求幫助解決這個問題。我正在做這個教程來重繪 記憶并用最新的技術更新我的知識:Developing Android Apps with Kotlin
https://classroom.udacity.com/courses/ud9012
在第 6 課第 10 課中,有以下源代碼:https ://github.com/udacity/andfun-kotlin-sleep-tracker/tree/Step.03-Solution-Create-RoomDatabase
@Test
@Throws(Exception::class)
fun insertAndGetNight() {
val night = SleepNight()
sleepDao.insert(night)
val tonight = sleepDao.getTonight()
assertEquals(tonight?.sleepQuality, -1)
}
假設它應該通過測驗,但在執行之后,它會回傳:
Test Passed: 0 passed.
在右邊的終端我可以讀到:
運行測驗
$ adb shell am instrument -w -m -e debug false -e class 'com.example.android.trackmysleepquality.SleepDatabaseTest#insertAndGetNight' com.example.android.trackmysleepquality.test/android.test.InstrumentationTestRunner
"Run Android instrumented tests using Gradle" option was ignored because this module type is not supported yet.
專案有什么問題,為什么沒有通過測驗?
我添加了一個手動撰寫的文本,結果是一樣的,0測驗通過。這是我添加的測驗:
@Test
fun addition_isCorrect() {
assertEquals(4, 2 2)
}
此外,我嘗試在測驗設定(轉到檔案>>設定>>測驗)中取消選中使用 Gradle 運行 Android 檢測測驗旁邊的框,結果相同。
uj5u.com熱心網友回復:
我下載了源代碼,發現 **testInstrumentationRunner ** 不見了,所以你需要在 gradle.build 中添加它
defaultConfig {
applicationId "com.example.android.trackmysleepquality"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
并且房間操作需要在協程范圍內,所以沒有它編譯器會出錯
@Test
@Throws(Exception::class)
fun insertAndGetNight() {
runBlocking {
val night = SleepNight()
sleepDao.insert(night)
val tonight = sleepDao.getTonight()
assertEquals(tonight?.sleepQuality, -1)
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/471545.html
