https://kotlinlang.org logo
#dagger
Title
# dagger
e

escodro

03/03/2021, 6:45 PM
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

wasyl

03/03/2021, 7:03 PM
Try
--stacktrace
, this may give you some more specific error
e

escodro

03/03/2021, 7:19 PM
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

allan.conda

03/04/2021, 3:24 AM
whats
CustomTestRunner
a

allan.conda

03/04/2021, 11:10 AM
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

escodro

03/04/2021, 12:09 PM
If only kapt could give an actual error message…
t

trevjones

03/04/2021, 8:49 PM
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

escodro

03/05/2021, 10:52 AM
Thanks, @trevjones! I definitely will give a try in the future. 😊 For now, I reverted to Koin so I can keep developing the app…
3 Views