Android code coverage generation though changes to build.xml and ant.properties

I am trying to create code coverage for Android for my Android testing project, which is testing an Android project that includes an external jar. When i run the command

ant emma install debug test

it shows the coverage of only the android project, but does not include the package and functions of the external bank. According to my research, I found that some changes should be made in the ant.properties file and the emma report tag in build.xml .

Any suggestions are welcome.

[change]

In a furthur study, I looked at a blog that says enter a variable

 tested.android.library.source.dir="path to external jars" in ant.properties 

and the same variable should be added to the report source path as

 <emma> <report sourcepath="${tested.project.source.absolute.dir}:${tested.project.lib.source.path.value}:${tested.android.library.source.dir}" verbosity="${verbosity}"> <!-- TODO: report.dir or something like should be introduced if necessary --> <infileset file="${out.absolute.dir}/coverage.ec" /> <infileset file="${tested.project.out.absolute.dir}/coverage.em" /> <!-- TODO: reports in other, indicated by user formats --> <html outfile="${out.absolute.dir}/coverage.html" /> </report> </emma> 

But still, the coverage does not show the features and package of external banners.

I wanted to know that my jars are not in the Android testing project, but in the Android test project. So, how to specify the path to these external jars in the ant.properties test project.

+2
source share
3 answers

I have been working on this for quite some time. See code coverage reports for library projects

External ATM support in the ADT-r20. I can only indicate the direction in which I work. I am working on modifying build.xml inside ant:

  <!-- This is macro that enable passing variable list of external jar files to ApkBuilder Example of use: <package-helper> <extra-jars> <jarfolder path="my_jars" /> <jarfile path="foo/bar.jar" /> <jarfolder path="your_jars" /> </extra-jars> </package-helper> --> <macrodef name="package-helper"> <element name="extra-jars" optional="yes" /> <sequential> <apkbuilder outfolder="${out.absolute.dir}" resourcefile="${resource.package.file.name}" apkfilepath="${out.packaged.file}" debugpackaging="${build.is.packaging.debug}" debugsigning="${build.is.signing.debug}" verbose="${verbose}" hascode="${manifest.hasCode}" previousBuildType="${build.last.is.packaging.debug}/${build.last.is.signing.debug}" buildType="${build.is.packaging.debug}/${build.is.signing.debug}"> <dex path="${intermediate.dex.file}"/> <sourcefolder path="${source.absolute.dir}"/> <jarfile refid="project.all.jars.path" /> <nativefolder path="${native.libs.absolute.dir}" /> <nativefolder refid="project.library.native.folder.path" /> <extra-jars/> </apkbuilder> </sequential> </macrodef> 

I'm not lucky yet.

+2
source

After many searches and attempts, I finally received a package of my external can in my main project. Just entered test.android.library.source.dir in ant.properties and build.xml

ant.properties: tested.android.library.source.dir = "Path to the libs folder of the main project where banks are present" Build.xml: under the emma tag in the report tag, add this variable, separated by a colon.

Now go to the command line and run

In the main project: android update project -p. In the test project: test update project Android -m "Path of the main project" -p.

Now copy the test target from build.xml (sdk / tools / ant / build.xml) and paste it into the build.xml of the test project above the line

  <import file="${sdk.dir}/tools/ant/build.xml" /> 

Remember to change the version tag for

Now open the command prompt again and run:

In the main project: ant emma debug install In the test project: ant test test emma debug install

The generated code coverage report will contain an external jar package

+2
source

I struggled with this for 2 days and, in the end, figured it out. The code snippet in the first message generates only the instrument report from the emma metadata file and the runtime coverage file, but does not execute the toolkit on the bank. To process the code, you will have to manipulate the byte code, for example, as the target for android ant build.xml does. Take a look at the element nested in <-compile> and you will see a comment as if it were just class files. To measure jars, add a pathpath element to the jars, as well as a class path.

Emma Documentation: http://emma.sourceforge.net/reference/ch02s03s02.html

 <emma enabled="${emma.enabled}" > <instr mode="fullcopy" outdir="${out.instr.dir}" merge="no" filter="${emma.filter}"> <instrpath> <fileset dir="${out.dir}" includes="**/*.jar" /> </instrpath> </instr> </emma> 

In Android build.xml. You just need to remove the instrpath attribute and make it look like the example above.

  756 <emma enabled="true"> 757 <instr verbosity="${verbosity}" 758 mode="overwrite" 759 instrpath="${out.absolute.dir}/classes" 760 outdir="${out.absolute.dir}/classes" 761 metadatafile="${emma.coverage.absolute.file}"> 762 <filter excludes="${emma.default.filter}" /> 763 <filter value="${emma.filter}" /> 764 </instr> 765 </emma> 

So something like this: (sorry line # s)

  756 <emma enabled="true"> 757 <instr verbosity="${verbosity}" 758 mode="overwrite" 760 outdir="${out.absolute.dir}/classes" 761 metadatafile="${emma.coverage.absolute.file}"> 759 <instrpath> 759 <pathelement path="${out.absolute.dir}/classes"/> 759 <fileset dir="${you-class-path}"/> 759 <include name="**/*.jar"/> 759 </fileset> 759 </instrpath> 762 <filter excludes="${emma.default.filter}" /> 763 <filter value="${emma.filter}" /> 764 </instr> 765 </emma> 
0
source

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


All Articles