So up to Dagger 2.11 I've been able to construct TestComponent's and Modules to enable key components to be injected into integration tests. This is great for Api tests and objects with heavy component requirements
Typically I would have code like this:-
class SpotifyApiTest {
lateinit var spotifyApi : SpotifyApi
@Inject set
lateinit var spotifyHelper : SpotifyIOHelper
@Inject set
@Before
fun setup() {
var context = InstrumentationRegistry.getInstrumentation().context
val testAppComponent = DaggerSpotifyTestComponent.builder()
.spotifyApiModule(SpotifyApiModule(context))
.build()
testAppComponent.inject(this)
}
@Test
......}
N/B remember to add the following to your gradle build file
kaptAndroidTest "com.google.dagger:dagger-compiler:$daggerVersion"
This approach works extremely well up to Dagger 2.11 but after that version Modules with parameterized constructors do not work preventing context being supplied let alone the application. So how can I use the new AndroidInjection() functionality for integration tests with the Dagger 2.16 for example?
Aucun commentaire:
Enregistrer un commentaire