I use hilt for dependency injection.
I use this articles for implements test.
https://developer.android.com/training/dependency-injection/hilt-testing
https://dagger.dev/hilt/testing.html
now wanna write test for my fragments.
I have a problem with add library.
this is my code
this class is my runner and use in gradle
class CustomTestRunner : AndroidJUnitRunner() {
override fun newApplication(
cl: ClassLoader?,
className: String?,
context: Context?
): Application {
return super.newApplication(cl, MyCustom_Application::class.java.name, context)
}
}
this is interface for hilt to generate an application class that i use in runner class
@CustomTestApplication(AndroidApplication::class)
interface MyCustom
this is my test class
@HiltAndroidTest
class SettingsActivityTest {
@get:Rule
var hiltRule = HiltAndroidRule(this)
// UI tests here.
@Test
fun test(){
// val activityScenario = launchActivity<MainActivity>()
}
}
my libraries
// 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")
but my problem:
when i add this line
kaptAndroidTest("com.google.dagger:hilt-android-compiler:2.34.1-beta")
gradle show this error message:
error: SettingsActivityTest_TestComponentDataSupplier is not abstract and does not override abstract method get() in TestComponentDataSupplier
public final class SettingsActivityTest_TestComponentDataSupplier extends TestComponentDataSupplier {
^
and when i use this line
kaptTest("com.google.dagger:hilt-android-compiler:2.34.1-beta")
android studio cant generate MyCustom_Application