Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:06:05+00:00 2026-06-05T05:06:05+00:00

My main project is an android library. I have created a test project with

  • 0

My main project is an android library.
I have created a test project with some unit test in it.
the tests run fine, but I am struggling to get the test coverage.
When I generate the coverage report, I only get the coverage of the tests cases,
but not of the library.
So it gives me almost 100% because 100% of the test are running.
but that doesn’t help me to tell what part of the library has been tested.

This is how I do it at the moment :

0) my project looks like this:
myLibraryProject        <- this is my android library project
myLibraryProject/tests  <- this is my android test project

1) build.xml file : (from myLibraryProject/tests directory)
>android update test-project --path . -m ../

2) Modify the ant.properties file :
#tested.project.dir=../
android.library.reference.1=..

3) only then can I run :
ant emma debug install test

if I don’t do step 2) then step 3) fails because the library project can not be installed

Any help would really be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:06:07+00:00Added an answer on June 5, 2026 at 5:06 am

    So here is the solution I found:

    Create a new build.xml in your test project
    copy the “test” target from android sdk build.xml file (I have used sdk20 preview 2 version)

    modify the sourcepath to point at the library project in the report section

    this is the one I use now :

     <!-- version-tag: custom -->
     <target name="test" depends="-test-project-check"
                description="Runs tests from the package defined in test.package property">
        <property name="test.runner" value="android.test.InstrumentationTestRunner" />
    
        <if condition="${project.is.test}">
        <then>
            <property name="tested.project.absolute.dir" location="${tested.project.dir}" />
    
            <!-- Application package of the tested project extracted from its manifest file -->
            <xpath input="${tested.project.absolute.dir}/AndroidManifest.xml"
                    expression="/manifest/@package" output="tested.project.app.package" />
        </then>
        <else>
            <!-- this is a test app, the tested package is the app's own package -->
            <property name="tested.project.app.package" value="${project.app.package}" />
        </else>
        </if>
    
        <property name="emma.dump.file" value="/data/data/${tested.project.app.package}/coverage.ec" /> 
    
        <if condition="${emma.enabled}">
            <then>
                <echo>WARNING: Code Coverage is currently only supported on the emulator and rooted devices.</echo>
                <run-tests-helper emma.enabled="true">
                    <extra-instrument-args>
                        <arg value="-e" />
                           <arg value="coverageFile" />
                           <arg value="${emma.dump.file}" />
                    </extra-instrument-args>
                </run-tests-helper>
                <echo level="info">Downloading coverage file into project directory...</echo>
                <exec executable="${adb}" failonerror="true">
                    <arg line="${adb.device.arg}" />
                    <arg value="pull" />
                    <arg value="${emma.dump.file}" />
                    <arg value="coverage.ec" />
                </exec>
                <echo level="info">Extracting coverage report...</echo>
                <emma>
                    <report sourcepath="../${source.dir}" verbosity="${verbosity}">
                        <sourcepath>
                          <dirset dir="${basedir}" >
                            <include name="../src" /> 
                            </dirset>
                        </sourcepath>
                        <infileset dir=".">
                            <include name="coverage.ec" />
                            <include name="coverage.em" />
                        </infileset>
                        <html outfile="coverage.html" />
                        <xml outfile="coverage/coverage.xml" />
                   </report>
                </emma>
                <echo level="info">Cleaning up temporary files...</echo>
                <delete file="coverage.ec" />
                <delete file="coverage.em" />
                <echo level="info">Saving the report file in ${basedir}/coverage/coverage.html and ${basedir}/coverage/coverage.xml</echo>
            </then>
            <else>
                <run-tests-helper />
            </else>
        </if>
    </target>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my android application I have created 2 projects. The main project and a
I have an Android Project(A) that's my main application, it references an Android library
I have a library-only Android eclipse project (no main class, only library classes) that
I have created an Android Library. That has all the main code. Also I
In vs2008 (C#): I have : a main project (windows app) WCF Library WCF
I have a Visual Studio solution containing 2 project: main project and test (via
I have an Android project that depends on an android library (apklib) project. The
I am writing an Android app. I have an activity in my main project
I have an Android library project (written by me and I have the sources)
I have an Android project that uses a library project (all of which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.