Hello, everyone! :blush: Is there any gotcha with...
# dagger
e
Hello, everyone! 😊 Is there any gotcha with Hilt + Instrumented Tests? I’m following the Hilt Testing documentation and the Crane sample and can’t make it work at all! If I run with
--debug
it only gives me the default:
Copy code
Execution failed for task ':app:kaptDebugAndroidTestKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
I’m migrating from Koin to Hilt but this is blocking me once I want to do some end to end tests in my application. Thanks a lot in advance! ❤️
Test class:
Copy code
@HiltAndroidTest
internal class HomeScreenTest {

    @get:Rule
    val composeTestRule = createComposeRule()

    @get:Rule
    var hiltRule = HiltAndroidRule(this)

    private val context = InstrumentationRegistry.getInstrumentation().targetContext

    @Before
    fun setup() {
        composeTestRule.setContent {
            NavGraph()
        }
    }
Custom runner on build.gradle
Copy code
android {
    defaultConfig {
      ...
      testInstrumentationRunner "com.escodro.alkaa.CustomTestRunner"
    }
build.gradle
Copy code
androidTestImplementation (Deps.hilt.android){
    exclude group: "androidx.fragment", module: "fragment"
    exclude group: "androidx.lifecycle", module: "lifecycle-runtime"
    exclude group: "androidx.lifecycle", module: "lifecycle-livedata-core"
}
androidTestImplementation Deps.test.runner
kaptAndroidTest Deps.hilt.compiler
w
Try
--stacktrace
, this may give you some more specific error
e
Yeah, actually I tried with all of them:
--stacktrace
,
--debug
, `--info`… The only way to see more helpful logs is removing the
kaptAndroidTest Deps.hilt.compiler
dependency, which does not help a lot.
😕 1
a
whats
CustomTestRunner
a
I meant the snippet. Perhaps you need to add this? @Config(application = HiltTestApplication::class)
Nvm, my tests dont have that and I use a custom runner with a custom application too.
e
If only kapt could give an actual error message…
t
you might try adding this to your gradle jvm args while debugging. its helped me get better output from other compiler issues.
-Dkotlin.compiler.execution.strategy="in-process"
e
Thanks, @trevjones! I definitely will give a try in the future. 😊 For now, I reverted to Koin so I can keep developing the app…