Closed tonilopezmr closed 8 years ago
Could be for DaggerMockRule? @fabioCollini
Hi Antonio, I am sorry but I can't investigate this problem until September. Are you using espresso or plain junit tests? Is it a multidex app?
Espresso and not multidex.
it's very weird, because when I run only a method or a class work's fine, but when I run a androidTest folder some mocks doesn't work.
My dagger2 configuration is fine, with Subcomponents
, using latest DaggerMock and Dagger2 versions.
You can have a look my repository and run only DetailActivityTest
and before run all androidTest
folder.
@tonilopezmr Since android Application is singleton, you need to reset its state for every test.
Here: https://github.com/tonilopezmr/Game-of-Thrones/blob/master/app/src/main/java/es/npatarino/android/gotchallenge/GotChallengeApplication.java#L49
You are caching characterComponent
instance, through effectively using Component
which was created by the first test.
Instead, you need to create new instance for every test. For example, reset reference to null at @After
.
@plastiv I will try, but, DaggerMockRule is reset before each test, right?
Oh good, @plastiv that's right.
I following this post to right dagger2 scope way.
DaggerMockRule will create new instance of the component for every test method (with new mock dependency instances), but your code should not cache it. And its yours responsibility to reset it. That's why devs hate singletons ;)
@plastiv Right
When Run only one class the Mock is successfully but when run all test doesn't replace my mock.
This is the test code
This is the inject code
This is the component
I don't know why because i think is the same execute one test or all test. :(
Do you have any idea?