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

扶醉桌前 提交于 2019-12-01 17:02:14

问题


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?


回答1:


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)




回答2:


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.



来源:https://stackoverflow.com/questions/7360972/how-can-i-use-filter-for-emma-when-building-android-test-with-ant

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