https://kotlinlang.org logo
#android
Title
# android
d

dave08

02/19/2018, 12:05 PM
@oleksiyp Is mockK.io compatible w/ Android Espresso?
o

oleksiyp

02/19/2018, 12:07 PM
I haven't tested that, dont know about other users, so have no idea.
n

neil.armstrong

02/19/2018, 12:08 PM
We are still using mockito, but adding a
TestAppModule
which provides your mocks should work just the same
Copy code
@Module
class TestAppModule(private val application: Application) {

    @Singleton
    @Provides
    fun provideMockNavigationRouter(): NavigationRouter = mock()
...
}
Copy code
val component = DaggerEspressoTestComponent
                .builder()
                .testAppModule(TestAppModule(application))
                .build()

        Application.dependencies = component
d

dave08

02/19/2018, 12:14 PM
@neil.armstrong You declare a
public var dependencies
in your Application's
companion object
? So the real dependencies get loaded and then you overwrite them w/ the test deps?
@oleksiyp It would have been nice to have something like https://github.com/fabioCollini/DaggerMock for mockK...
Or is it maybe compatible or easily adaptable to mockK?
n

neil.armstrong

02/19/2018, 12:16 PM
Yea we have a
EspressoTestComponent
which extends the
ApplicationComponent
so that we can override what gets injected
Copy code
@Singleton
@Component(modules = [TestAppModule::class])
interface EspressoTestComponent : ApplicationComponent {
Copy code
@Singleton
@Component(modules = [AppModule::class])
interface ApplicationComponent {
we also created a custom rule for setting it up
that’s where that component snippet is stolen from 🙂
d

dave08

02/19/2018, 12:18 PM
@neil.armstrong Do you have a little gist with a complete setup? I'm still not clear on all the details... 🤔
n

neil.armstrong

02/19/2018, 12:19 PM
If I get a minute later I’ll strip out any copyrighted stuff and send you it
d

dave08

02/19/2018, 12:19 PM
Thanks! 😃
o

oleksiyp

02/19/2018, 1:30 PM
Surely I'll check that