'How to inject repository dagger dependency instance in my integration tests?
I'm trying to access my repository dependency from my integration tests but I can't seem to find a way to do so.
@Singleton
@Component(
modules = [
RepositoryModule::class,
]
)
interface TestAppComponent : AppComponent {
@Component.Builder
interface Builder : AppComponent.Builder {
override fun build(): TestAppComponent
}
}
The repository module
@Module
interface RepositoryModule {
@Binds
fun repository(repo: Repository): IRepository
}
And in my integration test :
class AppIntegTests {
@Inject
lateinit var repository: IRepository
@BeforeTest
fun setup() {
repository.deleteAll()
}
@Test
fun testRoot() {
withTestApplication(config) {
handleRequest { method = HttpMethod.Get; uri = "/users" }.apply {
assertEquals(HttpStatusCode.OK, response.status())
}
// tests....
}
}
}
When doing this, I get lateinit property has not been initialized on my injected repository.
Is what I'm trying to do achievable with Dagger?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
