I am investigating code-coverage for our Android app. built with Gradle and Android Studio.
I need code-coverage reports in two situations: during manual tests, and during automated tests built with our Appium suite.
I need to get a proof-of-concept that JaCoCo can indeed do code coverage in this case.
Given that we need coverage for Appium and manual tests, I believe offline-instrumentation with JaCoCo is what I need.
I have succeeded in creating an instrumented APK.
But when I run the app manually, I keep seeing errors in the logcat W/System.err: java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system)
From JaCoCo docs as well as general Googling, I understand that Jacoco needs to know where to store the jacoco.exec file - and that I need to package a jacoco-agent.properties (containing a destfile property) with the APK.
I have tried putting jacoco-agent.properties in the "assets" folder of my app - it was packaged into the APK properly, but did not seem to have any effect (i.e Jacoco failed as usual) I tried putting it inside res - it did not get packaged into the APK. I tried res/raw and hit the error about a dash in the filename.
I am at my wit's end, and would really appreciate help. How do I package jacoco-agent.properties using my Gradle build into the APK, so that JaCoCo will read it?
True, I realized as much.
>
> Here is a working example for Android:
> https://github.com/Godin/jacoco-experiments/tree/android/android
>
Thanks. I did come across that in my searches, but that example is for Maven. I am unable to figure out how to do the same with Gradle (Android Studio uses Gradle)
I asked the same question in StackOverflow, the reply I received did not work.
(http://stackoverflow.com/questions/33182667/packaging-jacoco-agent-properties-into-an-apk-so-it-can-be-read)
I want to use jacoco for my appium test cases and manual testing using gradle. can you please help me about how to do it.?
Regards,
Anuja
Hi guys,
I guess from the latest update, it is clear that there is a gap in documentation for Jacoco - specifically in regards to making Jacoco work with Android Studio / Gradle for Manual Testing.
Existing docs either deal with code coverage for unit testing (doesn't apply to my case) or for an Ant/Maven setup (again does not apply).
An earnest appeal to the more knowledgeable folks out there to write a clear doc explaining how to make this combination work.
Thanks!
--
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
Any views expressed by the sender in this communication are those of the
sender alone and do not necessarily express the views or the policy of the
organization unless intended to do so. If you are not the named addressee
you should not disseminate, distribute or copy this e-mail. If you have
received this email in error please immediately notify *ad...@tsepak.com
<ad...@tsepak.com>* and delete this email from your system. If you are not
the intended recipient you are notified that disclosing, copying,
distributing or taking any action in reliance on the contents of this
information is strictly prohibited. Thank you.
As you said you managed to configure the jacoco with gradle with appium suit.
I am trying to do the same can you please share some more information on how you did it. It will be really helpful.
Thanks,
Anuja
I am unable to figure out how to do the same with Gradle (Android Studio uses Gradle)
I asked the same question in StackOverflow, the reply I received did not work.
(http://stackoverflow.com/questions/33182667/packaging-jacoco-agent-properties-into-an-apk-so-it-can-be-read)
Anuja
--
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
Any views expressed by the sender in this communication are those of the
sender alone and do not necessarily express the views or the policy of the
organization unless intended to do so. If you are not the named addressee
you should not disseminate, distribute or copy this e-mail. If you have
received this email in error please immediately notify *ad...@tsepak.com
<ad...@tsepak.com>* and delete this email from your system. If you are not
the intended recipient you are notified that disclosing, copying,
distributing or taking any action in reliance on the contents of this
information is strictly prohibited. Thank you.
Hi,
Could you provide me the build.gradle code to get the instrumented apk,
1.Configuring JaCoCo plugin in build.gradle (present inside 'app' folder ) as below
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.7.4+"
}
2. Enable Jacoco code coverage on the debug build in build.gradle (present inside 'app' folder ) at 'buildTypes' as below
debug {
testCoverageEnabled true
}
3. Add below line in your 'app/src/main/AndroidManifest.xml ' to access sdcard for writting coverage data
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
4. Add below lines in 'MainActivity.java' at end
protected void onStop()
{
super.onStop();
if(BuildConfig.DEBUG)
{
try {
Class<?> emmaRTClass = Class.forName("com.vladium.emma.rt.RT");
Method dumpCoverageMethod = emmaRTClass.getMethod("dumpCoverageData",coverageFile.getClass(), boolean.class, boolean.class);
dumpCoverageMethod.invoke(null, "/sdcard/coverage.exec", ture, false);
} catch (Exception e) {}
}
}
5.Build debug apk.
6..Install this apk in your device , and to do the test.
7.After testing kill your app.
8.Connect device with computer, run below command to get coverage data file from device
'adb pull /sdcard/coverage.exec'
9.Genrate coverage report using ant(with jacoco task) or jenkings (jacoco plugin) by using following:-
Copy classes from "D:\coverage\app\build\intermediates\classes\debug"
Copy source from "D:\coverage\app\\src\main\java"
Copy exec file from "D:\coverage\mycoverage.exec"
Add below as Exclusions:-
**/R.class,**/R$*.class,**/BuildConfig.*,**/Manifest*.*,**/*Fragment*.*,**/*Activity$*.*
Thanks
Abhishek Gupta
--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/vx0g_6TKY8Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/66a5b5af-8987-46a3-9902-0b6e0c7e079c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/CAP_M%3DRqmEd0eOZ3KEiGweFstWCGsd3eBUN8y_TUF2AOBQeZjdg%40mail.gmail.com.
Did it work for any .. esp Vishy as I am also facing same issue as Vishy..
Thanks,
Ramdas
Is there any way to get offline instrumentation done with jacoco using gradle?