In Kotlin Blog there is explanation how to make Dagger 2 work with Kotlin.
Everything worked like charm. So far… I just couldn’t make it to work in tests.
DaggerTestSomeComponent
was not generated from TestSomeComponent : SomeComponent
.
I’ve tried various combinations. Including creating absolutely new component just in tests. Still nothing.
Is there any workaround or could I provide some other details?
Dagger is a fully static, compile-time dependency injection framework for Java, Kotlin, and Android.
Dagger is implemented using Java's annotations model. It generates code at compile-time using an annotation processor. Annotation processors are supported in Kotlin with the kapt compiler plugin. They are enabled by adding id 'kotlin-kapt' to the top of the file below the id 'kotlin-android-extensions' line.
JUnit is a “Unit Testing” framework for Java Applications which is already included by default in android studio. It is an automation framework for Unit as well as UI Testing. It contains annotations such as @Test, @Before, @After, etc.
Make sure to add kaptAndroidTest 'com.google.dagger:dagger-compiler:2.0'
to your dependencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With