我在尝试使用Jetpack Compose构建的UI进行测试,并添加了以下依赖项来设置它
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.1.0"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.0.5"
为了测试,我刚开始编写以下内容
class LoginActivityComposeTest {
@get:Rule
val composeTestRule = createComposeRule()
@Test
fun socialPluginsTest() {
composeTestRule.setContent {
SocialLogins()
}
}
}
我尝试导入的 createComposeRule() 方法无法使用。我已经尝试手动导入 import androidx.compose.ui.test.junit4.createComposeRule,但是在此之后运行测试时会出现错误 Unresolved reference: junit4。这是我正在使用的完整 build.gradle 依赖项:
compose_version = '1.0.1' retrofit_version = '2.9.0'
implementation "androidx.core:core-ktx:1.7.0"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
implementation "androidx.activity:activity-compose:1.4.0"
implementation "androidx.navigation:navigation-compose:2.5.0-alpha01"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation "io.reactivex.rxjava2:rxkotlin:2.4.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0"
implementation 'com.google.android.gms:play-services-auth:20.1.0'
implementation "io.coil-kt:coil-compose:1.4.0"
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.1.0"
debugImplementation "androidx.compose.ui:ui-test-manifest:1.0.5"