How to supply Jacoco agent to an Android app?

血红的双手。 提交于 2019-12-21 06:06:34

问题


I am trying to get code coverage using Jacoco for manual testing. I am trying to use offline instrumentation. http://www.eclemma.org/jacoco/trunk/doc/offline.html

In there it mentions: Configuration File: If a file jacoco-agent.properties is supplied on the classpath options are loaded from this file.

My question is how do I supply this? On some other forum, I saw that jacoco-agent.properties needs to be deployed with the app.

I tried putting jacoco-agent.properties under the res/raw, but it complained about "-" in the file name.

I tried putting this under the root directory it didn't take any effect.

I was wondering how could I setup\run jacoco so that it uses jacoco-agent.properties?


回答1:


Well, at least for an Ant command line build the trick was to put jacoco-agent.properties in the src directory, which makes it get packaged as-is into the root of the APK file, from where it seems to be properly read (i.e. I can see setting the destfile property having an effect on where the execution data file is being created).

However, the created jacoco.exec file was always empty for me (like also mentioned here), probably because JaCoCo only writes the execution data at JVM termination, but Android's Dalvik VM does not terminate when the app stops.

The way we currently solve this is to explicitly call

org.jacoco.agent.rt.RT.getAgent().getExecutionData(false)

and write the returned byte array to a file when our custom test runner finishes.



来源:https://stackoverflow.com/questions/19327112/how-to-supply-jacoco-agent-to-an-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!