Generating android code coverage though changes in build.xml and ant.properties
Asked Answered
Y

3

2

I have been trying to generate android code coverage for my android test project which tests a android project which includes a external jar. When I run command

ant emma install debug test

it shows coverage of only the android project but does not include the package and functions of the external jar included. As per my researches I have found that some changes should be done in ant.properties file and emma report tag in build.xml.

Any suggestions are most welcome.

[Edit]

On furthur study, I went through a blog which says enter the variable

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

and same variable should be added in report sourcepath 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 is not showing functions and package of External jar.

I wanted to know that my jars are not in the android test project but in the android project which is tested. So how to give path to those external jars in ant.properties of the test project.

Yokel answered 20/11, 2012 at 4:9 Comment(1)
I have been trying from past 24 hours...but still no result.Any suggestions...please helpYokel
F
2

I am also working on the same from quite some time. Refer to code coverage reports for library projects

External jars coverage support is in ADT-r20. I can only point to the direction I am working. 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 have no luck till yet.

Fayum answered 20/11, 2012 at 10:3 Comment(0)
Y
2

After lots of searching and trying , finally got the package of my External jar in my Main project. Just entered tested.android.library.source.dir in ant.properties and build.xml

ant.properties: tested.android.library.source.dir="Path to libs folder of main project where jars are present" Build.xml : Under emma tag in report tag add this variable seperated by colon.

Now go to command prompt and run

In Main Project :android update project -p . In Test Project: android update test-project -m "Path of main project" -p .

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

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

Dont Forget to Change Version Tag to

Now Again open command prompt and run:

In Main Project: ant emma debug install In Test Project: ant emma debug install test

Your Code coverage report generated will contain the package of the external jar

Yokel answered 5/12, 2012 at 10:51 Comment(1)
I was successfull in getting the package of my external jar in my code coverage report, but still the hitting percentage is 0% for my jar packages and classes. What am I doing wrong?Yokel
R
0

I struggled with this for 2 days and eventually figured it out. The code snippet in the first post only generates instrument report from emma metadatafile and runtime coverage file but does not perform instrumentation on jar. To instrument the code you will have to manipulate the byte code, like how android ant build.xml target does it. Take a look at the element nested in <-compile> and you will see comment like it is only instrumenting class files. To instrument the jars add a classpath like element to the jars along with path to class.

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's build.xml. One just have to delete 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: (pardon the 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>
Ruthful answered 24/1, 2014 at 6:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.