gpt4 book ai didi

android - 添加库以进行刀柄测试的问题

转载 作者:行者123 更新时间:2023-12-05 00:10:56 25 4
gpt4 key购买 nike

我使用 hilt 进行依赖注入(inject)。
我使用这篇文章进行工具测试。
https://developer.android.com/training/dependency-injection/hilt-testing
https://dagger.dev/hilt/testing.html
现在想为我的 fragment 写测试。
我在添加库时遇到问题。
这是我的代码
这门课是我的运行者,在 gradle 中使用

class CustomTestRunner : AndroidJUnitRunner() {
override fun newApplication(
cl: ClassLoader?,
className: String?,
context: Context?
): Application {
return super.newApplication(cl, MyCustom_Application::class.java.name, context)
}
}
这是 hilt 生成我在 runner 类中使用的应用程序类的接口(interface)
@CustomTestApplication(AndroidApplication::class)
interface MyCustom
这是我的测试课
@HiltAndroidTest
class SettingsActivityTest {

@get:Rule
var hiltRule = HiltAndroidRule(this)

// UI tests here.

@Test
fun test(){
// val activityScenario = launchActivity<MainActivity>()
}
}
我的图书馆
// For instrumented tests.
androidTestImplementation("com.google.dagger:hilt-android-testing:2.28-alpha")

// ...with Kotlin.
kaptAndroidTest("com.google.dagger:hilt-android-compiler:2.34.1-beta")

androidTestImplementation("junit:junit:4.12")
androidTestImplementation ("androidx.test.ext:junit:1.1.2")
androidTestImplementation ("androidx.test.espresso:espresso-core:3.3.0")
但我的问题:
当我添加这一行
kaptAndroidTest("com.google.dagger:hilt-android-compiler:2.34.1-beta")
gradle 显示此错误消息:
error: SettingsActivityTest_TestComponentDataSupplier is not abstract and does not override abstract method get() in TestComponentDataSupplier
public final class SettingsActivityTest_TestComponentDataSupplier extends TestComponentDataSupplier {
^
当我使用这条线时
kaptTest("com.google.dagger:hilt-android-compiler:2.34.1-beta")
android studio 无法生成 MyCustom_Application

最佳答案

我以前遇到过这个问题。出现此问题是由于版本不兼容。
使用:

androidTestImplementation("com.google.dagger:hilt-android-testing:2.34.1-beta")
kaptAndroidTest("com.google.dagger:hilt-android-compiler:2.34.1-beta")
implementation("com.google.dagger:hilt-android:2.34.1-beta") //hilt dependency
而不是这个:
androidTestImplementation("com.google.dagger:hilt-android-testing:2.28-alpha")
kaptAndroidTest("com.google.dagger:hilt-android-compiler:2.34.1-beta")

关于android - 添加库以进行刀柄测试的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68259101/

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