Android Code Coverage

I have set up Emma Code Coverage for our test application with the help from bootstraponline sometime back. It worked great so far.

I want to know the importance of the second parameter in api
endTestCoverage(String intent,
String path)

Where does it pull this file to?
Suppose we use dynamic name [Ex : Systemtime()+"_coverage.ec" as fileName], how do we use that in this api ?

1 Like

Just wanted to share the link to earlier discusssion :
https://groups.google.com/forum/#!topic/appium-discuss/fLtG6NqzhDo

I’m not sure. It’s on my list to improve the documentation / examples around coverage.

Just observed documentation is very well updated @ http://appium.io/slate/en/v1.0.0/?java#android-coverage

Only one question still remains though -

How can we generate multiple coverage.ec files for different test runs without changing fileName in EndEmmaBroadcast Class.
Also, what location do this file get pulled/saved to?

1.Android code coverage links:
appium docs
an appium issue

2.Is there anything for iOS? I searched and could not find any discussions on it which I guess means it’s either trivial or very difficult…?

Yes iOS has something very similar.


https://dl.dropboxusercontent.com/u/9302287/Code%20Coverage%20on%20iOS.pdf

You’d configure your app to dump the coverage data on exit and then you’ll be able to collect & inspect it after the appium test runs.

Thank you, I’ll check that out

I am curious about iOS coverage.
I have been doing it for Unit Test, no problem.
However with Appium test, I don’t even need the source code to run the app. How the coverage result show when I open it? Where do I find the coverage files? In the Trace directory?

I am facing problem with Emma code Coverage on Appium :
I used this link https://github.com/appium/appium/blob/0.18.x/docs/en/android_coverage.md
When I have androidCoverage capability set to true, it does NOT launch my application.
But, if I dont have that capability, app launches successfully and test runs well.
It keeps waiting for the activity to be in focus. Pls help!

Note: Also my app project is in gradle, would that need any different settings?

@bootstraponline how do I make the setup in gradle?
I did the emma setup from the link above and get this issue with adb pull as no coverage.ec file is generated.
executing cmd: /Applications/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb -s 04157df4bdd50832 shell “rm -rf /data/local/coverage/coverage.ec”
e[36minfoe[39m: [debug] Broadcasting: am broadcast -a com.salesforce.chatter.END_EMMA
e[36minfoe[39m: [debug] executing cmd: /Applications/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb -s 04157df4bdd50832 shell “am broadcast -a com.salesforce.chatter.END_EMMA”
e[36minfoe[39m: [debug] executing cmd: /Applications/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb -s 04157df4bdd50832 shell “ps”
e[36minfoe[39m: [debug] process: com.salesforce.chatter exists:true
e[36minfoe[39m: [debug] executing cmd: /Applications/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb -s 04157df4bdd50832 shell “ps”
e[36minfoe[39m: [debug] process: com.salesforce.chatter exists:false
e[36minfoe[39m: [debug] executing cmd: /Applications/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb -s 04157df4bdd50832 pull /data/local/coverage/coverage.ec “/var/folders/_0/z6c2197x0tz4cg6xgk0rf3cs83wsh8/T/appium115624-38814-zef78a.ec”
e[36minfoe[39m: [debug] Responding to client with error: {“status”:13,“value”:{“message”:“An unknown server-side error occurred while processing the command. (Original error: Command failed: /bin/sh -c /Applications/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb -s 04157df4bdd50832 pull /data/local/coverage/coverage.ec “/var/folders/_0/z6c2197x0tz4cg6xgk0rf3cs83wsh8/T/appium115624-38814-zef78a.ec”\nremote object ‘/data/local/coverage/coverage.ec’ does not exist\n)”,“killed”:false,“code”:1,“signal”:null,“cmd”:"/bin/sh -c /Applications/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb -s 04157df4bdd50832 pull /data/local/coverage/coverage.ec “/var/folders/_0/z6c2197x0tz4cg6xgk0rf3cs83wsh8/T/appium115624-38814-zef78a.ec”",“origValue”:“Command failed: /bin/sh -c /Applications/adt-bundle-mac-x86_64-20140702/sdk/platform-tools/adb -s 04157df4bdd50832 pull /data/local/coverage/coverage.ec “/var/folders/_0/z6c2197x0tz4cg6xgk0rf3cs83wsh8/T/appium115624-38814-zef78a.ec”\nremote object ‘/data/local/coverage/coverage.ec’ does not exist\n”},“sessionId”:“3481b038-c67b-4603-b85e-6516d5beae07”}
e[36minfoe[39m: e[37m<-- POST /wd/hub/session/3481b038-c67b-4603-b85e-6516d5beae07/appium/app/end_test_coverage e[39me[31m500e[39me[90m 725.448 ms - 1055e[39m e[90me[39m

I recommend opening an issue on github.

Actually, here is the issue you should comment on:

Is there a code coverage available for ios ? I am using apipum 1.6.3 which uses XCUI test framework. How to get code coverage from appium tests for ios app?

Can anyone here write a proper guide for android code coverage? What libraries to install and step by step process?

I still haven’t seen any proper documentation for android code coverage and its 2022. I have tried multiple times using the given documentation since 2016 still no luck. Can someone point me if its achievable