How can I run Jacoco in android studio to cover code

I already have a debugging taste in Android studio. My gradle configuration file for my application module contains the following:

debug{ testCoverageEnabled true } 

then I ran the following command in the terminal:

 gradlew createDebugCoverageReport 

and indeed, I get a report, but the application also crashes with a read-only error, and I cannot figure it out. I am using mac. Here is the stack trace:

  **java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system)** 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at libcore.io.IoBridge.open(IoBridge.java:416) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at java.io.FileOutputStream.<init>(FileOutputStream.java:88) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at org.jacoco.agent.rt.internal_932a715.output.FileOutput.openFile(FileOutput.java:67) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at org.jacoco.agent.rt.internal_932a715.output.FileOutput.startup(FileOutput.java:49) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at org.jacoco.agent.rt.internal_932a715.Agent.startup(Agent.java:122) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at org.jacoco.agent.rt.internal_932a715.Agent.getInstance(Agent.java:50) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at org.jacoco.agent.rt.internal_932a715.Offline.<clinit>(Offline.java:31) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at mypackage.org.duckduck.MainApplication.$jacocoInit(MainApplication.java) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at mypackage.org.duckduck.MainApplication.<clinit>(MainApplication.java) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at java.lang.Class.newInstanceImpl(Native Method) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at java.lang.Class.newInstance(Class.java:1319) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at android.app.Instrumentation.newApplication(Instrumentation.java:983) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at android.app.Instrumentation.newApplication(Instrumentation.java:968) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at android.app.LoadedApk.makeApplication(LoadedApk.java:499) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4480) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at android.app.ActivityThread.access$1300(ActivityThread.java:146) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at android.os.Handler.dispatchMessage(Handler.java:99) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at android.os.Looper.loop(Looper.java:137) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at android.app.ActivityThread.main(ActivityThread.java:5168) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at java.lang.reflect.Method.invokeNative(Native Method) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at java.lang.reflect.Method.invoke(Method.java:511) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:564) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at dalvik.system.NativeStart.main(Native Method) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• Caused by: libcore.io.ErrnoException: open failed: EROFS (Read-only file system) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at libcore.io.Posix.open(Native Method) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• at libcore.io.IoBridge.open(IoBridge.java:400) 03-01 00:04:56.871 19006-19006/mypackage.org.duckduck W/System.errīš• ... 24 more 
+6
source share
3 answers

I had a problem with jacoco on a USB device. Using Genymotion solved the problem.

0
source

Since I don’t see your entire gradle file, I’m not sure that you already have this correctly, but one sentence does not apply the jacoco plugin explicitly, if you are in the gradle file, gradle the latest version comes with JaCoCo.

This violated my tests until recently, when I tried without this line.

Another thing, I just ran

gradle connectedCheck

from the terminal (Mac) or the command line (windows), and this creates for me a report on the coverage of HTML code.

Hope this fixes your issue as well.

0
source

This warning seems irrelevant :

The error message disappeared when installing the read-write root file system

 mount -o remount,rw rootfs / 

and just set write permissions for all users (just do it on the emulator !!!, it’s really unsafe)

 chmod 777 / 

Unfortunately, my tests were broken before and after, changing this did not fix them at all.

So, if there is no real problem, you can simply consider this as a message that does not require action .

0
source

Source: https://habr.com/ru/post/983172/


All Articles