How can I use a filter for emma when creating an Android test using ant?

I know how to use emma in ant when creating my Android testing project, but I can not find any tips on how to use filters when using the SDK. The emma website explains this when you call emma yourself, but in the SDK build files for Android, emma is not called in ant files or on the command line, so I cannot add filter parameters.

Are there any suggestions?

+7
source share
2 answers

With SDK Tools r18 you can just add

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

to ant.properties of your project ( do not test the project )

+10
source

This depends on the version of the SDK used, in particular the included build files found in the <android-sdk>/tools/ant directory.

Android SDK> = 18

As in the r18 SDK and above, it is as simple as adding a property to your ant.properties file of the target (non-test) project. For example, use

 emma.filter=-*.test.* 

To exclude all classes from the test suite. The syntax of the emma filter can be found in the emma documentation .

Android SDK <18

There is a problem for this . This includes the following:

  • you need to modify the build file for your target project (not a test project).
  • modify the assembly file by copying the -emma-instrument target from the imported android assembly files (you should find an explanation of this method in the standard project assembly file that you get by running android create/update project )
  • change the goal according to the related problem, it will look like this:

     <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> 
  • explanation of exception filter syntax is available in emma documentation

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

For me, it worked like a charm on SDK r13 tools.

+5
source

All Articles