How can I use filter for emma when building Android test with ant?
Asked Answered
D

2

7

I know how to use emma in ant when building my android test project but I can't find any tips on how to use filters when using the SDK. The emma website explains it when calling emma yourself but in the Android SDK build files emma is not called in the ant files or on the commandline so I'm not able to add the filter options.

Anyone any suggestions?

Dalpe answered 9/9, 2011 at 11:29 Comment(1)
See here to exclude library projects #12506896Biosynthesis
G
10

As of SDK Tools r18 you can simply add

emma.filter=-com.your.excluded.package.*

to the ant.properties of your project (not Test project)

Galvani answered 16/6, 2012 at 7:21 Comment(4)
Yeah... It's a pity I didn't follow up and post the r18+ variant of emma filters as an update to my answer, so now it got unaccepted :-/ Nevertheless, I post the update now.Softfinned
Ups... sorry, I didn't plan to "steal" you acceptance points - no offence.:) I just wanted to post an update to your answer. I was fighting the problem mentioned by Huupke few days ago, and found this solution after examining sdk-tools\ant\build.xml file in r18.Galvani
No big deal, that's life ;). In fact I could see myself posting an answer like yours, although from my current point of view an answer comment would've been almost a win/win situation (as I would've upvoted the comment). But as I said: No big deal.Softfinned
It seems not to work on android v21.1.0 I had to add it directly on the command line as explained hereCookbook
S
5

It depends on the SDK version you are using, specifically the included build files found in <android-sdk>/tools/ant directory.

Android SDK >= 18

As of the SDK r18 and above it's as simple as adding a property to your ant.properties file of the target (not test) project. So for example use

emma.filter=-*.test.*

To exlude all classes from a test package. You can find the emma filter syntax in the emma documentation.

Android SDK < 18

There's an issue for this. It involves the following:

  • you have to modify the build file for your target project (not the test project)
  • modify the build file by copy'n'pasting the -emma-instrument target from the imported android build files (you should find an explanation of this method in the standard project build file which you get by running android create/update project)
  • modify the target according to the linked issue, it'll look like:

    <target name="-emma-instrument" depends="compile">
        <echo>Instrumenting classes from ${out.absolute.dir}/classes...</echo>
        <!-- It only instruments class files, not any external libs -->
        <emma enabled="true">
            <instr verbosity="trace1"
                   mode="overwrite"
                   instrpath="${out.absolute.dir}/classes"
                   outdir="${out.absolute.dir}/classes">
                <filter excludes="*.R,*.R$$*,${emma.exclusion.pattern}" />
            </instr>
            <!-- TODO: exclusion filters on R*.class and allowing custom exclusion from
                 user defined file -->
        </emma>
    </target>
    
  • an explanation of the exclusion filter syntax is available on the emma documentation

  • either modify the modification or use the proposed ant property emma.exclusion.pattern to provide your own exclusions

For me this has worked like a charm on SDK tools r13.

Softfinned answered 29/11, 2011 at 12:41 Comment(5)
There is no target named "-emma-instrument" and "comple" in tools/ant/build.xml of android sdk R15, so I added the <filter excludes=".R,.R$$*,${emma.exclusion.pattern}" /> to the <emma><instr> statement in target "-compile" of tools/ant/build.xml, but it still doesn't work the coverage data of R.java still exist.Sazerac
@Sazerac Obviously they refactored out the emma-instrument target after r13 where it was included in the compile target before. I'm sorry I cannot help with your problem as I've got no r13 laying around. So we've learned that the Android engineers change/improve the build system quite often.Softfinned
Thanks for your reply, I've updated to Android SDK R20 and using emma.filter in ant.properties.Sazerac
Doesn't seem to be working for me, with SDK 19. I've echoed the property value for emma.filter in build.xml to check it's read correctly from ant.properties, and then checked in the SDK/build.xml file that its executing emma with "<filter value="${emma.filter}" />" - so not sure what´s failing.Class
This might have something to do with it: "Override ignored for property "emma.filter"" from ant -dClass

© 2022 - 2024 — McMap. All rights reserved.