简体   繁体   中英

How can i run Jacoco in android studio for code coverage

I have a debug flavor in android studio already. My gradle config file for my app module contains the following:

debug{
    testCoverageEnabled true
}

then i run the following command in the terminal:

gradlew createDebugCoverageReport

and indeed I get a report but the app also crashes with a read only error and I cannot seem to figure it out. I'm using a 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

Since, I dont see your entire gradle file I'm not sure if you already have this the right way but one suggestion is don't apply the jacoco plug-in explicitly if you are in the gradle file. Gradle's most recent version comes packaged with JaCoCo.

This was breaking my tests until recently when I tried without that line.

Another thing is I just run

gradle connectedCheck

from the terminal(Mac) or command prompt (windows) and this generates the html code coverage report for me.

Hopefully trying this fixes your issue too.

I had the same problem running jacoco on an USB device. Using Genymotion solved the issue.

This warning seems irrelevant :

The error message went away when mounting the root file system read-write

mount -o remount,rw rootfs /

, and just setting write permissions for all users (only do this on an emulator!!!, it is really insecure)

chmod 777 /

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

So unless there is a real problem, you could just treat this as a message that requires no action .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM