Closed cooldude77 closed 3 years ago
If you have a minimal reproducing example we can try to take a look. Just from the stack trace it's difficult to say if it's due to Dagger/Hilt because the error is occurring within ActivityScenario.<init>
. FWIW, I found a similar issue on SO which has this issue when using just ActivityScenario
and not Dagger.
Hey,
I have opened up my repo for your testing. Please run testActivityStarted
of MainActivityTest
to check it . Thanks a lot
Hi @cooldude77, thanks for the repo.
I did get an error when running testActivityStarted
, but it was a different error:
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class com.instanect.task.business_layer.database.TaskDatabaseHelper.
Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.
IMPORTANT INFORMATION FOR ANDROID USERS:
The regular Byte Buddy mock makers cannot generate code on an Android VM!
To resolve this, please use the 'mockito-android' dependency for your application:
Following the directions in the error message above, I was able to fix this by swapping this with:
androidTestImplementation group: 'org.mockito', name: 'mockito-android', version: '2.22.0'
I'm not sure if that change will also get you past your issue as well, but once that is fixed I get a new error:
java.lang.RuntimeException: No activities found. Did you forget to launch the activity by calling getActivity() or startActivitySync or similar?
Which makes sense because there is no activity being launched in MainActivityTest
.
Did you mean to add an ActivityScenario
or ActivityScenarioRule
to launch an activity in this test?
Hey @bcorso
Thanks for checking this out and replying. Sorry for the delay.
I was struggling with problem that you had identified. The test case resolved to satisfaction . The exception with jar file is not gone though and I have placed a ticket with android. I don't think that HILT is causing that problem at all.
I will keep my repo open for 1-2 weeks in case you need to take a look at it again.
Thanks again
Hey @cooldude77 , what actually resolved the issue with the exception of the jar file? Were your tests failing because of the exception?
Hi,
So I am trying to start an activity and do a mock injection using HILT and ESPRESSO. Upon running the test , I get this strange error This was not so until I started using hilt and mocking database dependencies in the project.
Similar issue here https://stackoverflow.com/questions/58061693/espresso-generating-filenotfoundexception-when-used-with-dagger