Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dagger 2 in Unit tests with Kotlin

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?

like image 484
Martynas Jurkus Avatar asked Aug 15 '15 21:08

Martynas Jurkus


People also ask

Does dagger work with Kotlin?

Dagger is a fully static, compile-time dependency injection framework for Java, Kotlin, and Android.

How do you use the kotlin dagger?

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.

Which Java framework is used to write unit tests in Android?

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.


1 Answers

Make sure to add kaptAndroidTest 'com.google.dagger:dagger-compiler:2.0' to your dependencies.

like image 65
Kirill Rakhman Avatar answered Sep 22 '22 07:09

Kirill Rakhman