-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Description
Hi,
first of all congratulations and thanks for the library, because to be honest setting up Dagger is really cumbersome.
I'm trying DaggerMock for the first time to mock my dependencies in the instrumented tests, and I'm getting the errors here.
I'm having a fairly simple test just to make sure it works:
@RunWith(AndroidJUnit4::class)
class GoalEvaluationEntryFragmentTest {
@get:Rule
var activityRule = ActivityTestRule(GoalEvaluationActivity::class.java)
@get:Rule
val rule = espressoDaggerMockRule()
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
EspressoTestUtil.disableProgressBarAnimations(activityRule)
val fragment = GoalEvaluationEntryFragment()
(activityRule.activity as FragmentActivity).supportFragmentManager.beginTransaction()
.replace(R.id.mainContainer, fragment).commit()
}
@Test
fun a() {
}
}
and I'm using the espressoDaggerModule
in the examples but adapted to my project:
fun espressoDaggerMockRule() =
DaggerMock.rule<AppComponent>(
MainModule(),
ServicesModule(app),
ModelsModule(app)
) {
set { component -> app.component = component }
}
val app: MDApplication get() = ApplicationProvider.getApplicationContext<Context>() as MDApplication
And the MainModule
for example is:
@Module
@OpenForTesting
class MainModule {
@Provides
@Singleton
fun provideUiHandler(): Handler = Handler(Looper.getMainLooper())
@Provides
@Singleton
fun provideSnackBar(): SnackBar = SnackBar()
}
I tried to use both Kotlin AllOpen plugin and also DexOpener, but I'm always getting the same issue (the one in pastebin).
If I remove @get:Rule val rule = espressoDaggerMockRule()
from the test, it all works (but I can't mock my dependencies of course).
Is there anything else I need to do that I've maybe missed?
Thanks!
Metadata
Metadata
Assignees
Labels
No labels