gpt4 book ai didi

android - AndroidX 的未解决引用 ActivityTestRule

转载 作者:IT老高 更新时间:2023-10-28 13:39:45 25 4
gpt4 key购买 nike

我正在尝试使用 androidX espresso 库通过仪器测试来测试我的 UI。在我的年级,我有:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: "kotlin-kapt"

android {
compileSdkVersion 28
defaultConfig {
applicationId "it.zehus.mybike"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
android.defaultConfig.manifestPlaceholders = ['appAuthRedirectScheme': 'net.openid.appauthdemo']
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

def lifecycle_version = "2.0.0"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"

// room persistence library
def room_version = "2.1.0-alpha04"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version" // use kapt for Kotlin
// optional - Coroutines support for Room
implementation "androidx.room:room-coroutines:$room_version"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'

// Espresso
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation project(path: ':remotemanager')
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.21"

androidTestImplementation 'androidx.test.ext:junit:1.1.0'
// required if you want to use Mockito for unit tests
testImplementation 'org.mockito:mockito-core:2.24.5'
// required if you want to use Mockito for Android tests
androidTestImplementation 'org.mockito:mockito-android:2.24.5'
// Bluetooth sdk
implementation project(path: ':bluetoothmanager')
// Custom views
implementation project(path: ':customviews')


}

documentation 中所述我正在尝试在我的测试中导入 ActivityTestRule 类,但引用未解析。

import androidx.test.filters.LargeTest
import androidx.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
// unresolved reference here
import androidx.test.rule.ActivityTestRule
import it.zehus.mybike.ui.ride.RideActivity


/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
// deprecated here
@RunWith(AndroidJUnit4::class)
@LargeTest
class FragmentDashboardUiTest {
@get:Rule // unresolved reference here
val activityRule = ActivityTestRule(RideActivity::class.java)

@Test
fun myClassMethod_ReturnsTrue() { }
}

是我做错了什么还是 AndroidX 测试库中存在问题?

最佳答案

我从 this 得知AndroidX 中 ActivityTestRule 类位于 androidx.test.rule 下的文档页面。为了导入包,我简单地添加了:

 androidTestImplementation 'androidx.test:rules:1.2.0'

给我的毕业生。

总结一下我的 gradle 现在包含:

// Espresso
// Core library
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'

关于android - AndroidX 的未解决引用 ActivityTestRule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54809410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com