{HILT] Testing with hilt is crashing
See original GitHub issueHi,
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.
E/System: Unable to open zip file: /data/user/0/com.*****/cache/oestHVv0.jar
E/System: java.io.FileNotFoundException: /data/user/0/com.*****/cache/oestHVv0.jar (No such file or directory)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:265)
at java.util.zip.ZipFile.<init>(ZipFile.java:187)
at java.util.jar.JarFile.<init>(JarFile.java:169)
at java.util.jar.JarFile.<init>(JarFile.java:106)
at libcore.io.ClassPathURLStreamHandler.<init>(ClassPathURLStreamHandler.java:46)
at dalvik.system.DexPathList$Element.maybeInit(DexPathList.java:777)
at dalvik.system.DexPathList$Element.findResource(DexPathList.java:804)
at dalvik.system.DexPathList.findResources(DexPathList.java:599)
at dalvik.system.BaseDexClassLoader.findResources(BaseDexClassLoader.java:248)
at java.lang.ClassLoader.getResources(ClassLoader.java:839)
at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:349)
at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:402)
at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:488)
at androidx.test.internal.platform.ServiceLoaderWrapper.loadService(ServiceLoaderWrapper.java:46)
at androidx.test.internal.platform.ServiceLoaderWrapper.loadSingleService(ServiceLoaderWrapper.java:69)
at androidx.test.core.app.ActivityScenario.<init>(ActivityScenario.java:145)
at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:206)
at com.instanect.task.MainActivityTest.init(MainActivityTest.kt:48)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:76)
at dagger.hilt.android.internal.testing.MarkThatRulesRanRule$1.evaluate(MarkThatRulesRanRule.java:92)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2214)
Similar issue here https://stackoverflow.com/questions/58061693/espresso-generating-filenotfoundexception-when-used-with-dagger
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Android Hilt Crashes on Startup - kotlin - Stack Overflow
After tinkering around with different version values it looks like downgrading the app dependency classpath "com.google.dagger:hilt-android- ...
Read more >Hilt testing guide | Android Developers
This makes Hilt work for all of the instrumented tests in your project. Perform the following steps:
Read more >[Solved]-Hilt - Dependency cycle crash-kotlin - appsloveworld
Coding example for the question Hilt - Dependency cycle crash-kotlin. ... How to mock the view model with Hilt for unit testing fragments?...
Read more >Testing - Hilt - Dagger
Note: Currently, Hilt only supports Android instrumentation and Robolectric tests (although, see here for limitations when running Robolectric tests via ...
Read more >Full Guide to Testing Android Applications in 2022
Setting up Hilt testing; Replacing Hilt modules for tests ... mapping won't have any sources and will crash with a NullPointerException .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @cooldude77, thanks for the repo.
I did get an error when running
testActivityStarted
, but it was a different error:Following the directions in the error message above, I was able to fix this by swapping this with:
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:
Which makes sense because there is no activity being launched in
MainActivityTest
.Did you mean to add an
ActivityScenario
orActivityScenarioRule
to launch an activity in this test?Hey @cooldude77 , what actually resolved the issue with the exception of the jar file? Were your tests failing because of the exception?