I want to get code coverage when doing unit tests. I run ant coverage using the standard android build.xml file for tests.
Tests work well. The last lines from ant coverage are
Tests run: 59, Failures: 1, Errors: 4 Generated code coverage data to /data/data/my.package/files/coverage.ec
But the coverage.ec file is only 37 bytes long and almost empty.
Running emma reports this
no collected coverage data found in any of the data files [all reports will be empty]
and generates a beautiful report with ZEROES in each of its fields.
I believe emma should generate higher .ec coverage.
What am I doing wrong?
--- update ---
There was some deep digging. It seems that most things are good, except for generating a coverage result.
1) He compiles everything that says
[javac] /blabla/android-sdk-linux_x86/tools/ant/main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds [javac] Compiling 88 source files to /blabla/project/tests/instrumented/classes [javac] Note: Some input files use unchecked or unsafe operations. [javac] Note: Recompile with -Xlint:unchecked for details.
2) It executes <instr> with mode="overwrite" for the test project. The path is fine.
-emma-tool: [echo] Instrument classes from / blabla / project / tests / instrumented / classes ...
As a result, there is a * .em file with metadata for 98 classes.
3) Some standard conversion of android to dex, package for alignment, alignment according to zip. The result is / blabla / project / tests / instrumented / project -debug.apk.
4) Install this debug.apk project on the emulator.
5) Compilation of test design. compilation: [javac] / blabla / android-sdk / android-sdk-linux_x86 / tools / ant / main_rules.xml: 384: warning: 'includeantruntime' was not installed, default is build.sysclasspath = last; set to false for repeated assemblies [javac] Compiling 110 source files in / blabla / project / tests / bin / classes
The source files include all previous files plus tests (110 = 88 + tests), as indicated in build.properties (multiple source.dir, separated by a ";").
6) Resources, Dex, signature, zip align ... Result of projectTest-debug.apk
7) Install projectTest-debug.apk on the emulator.
8) Running tests through am where "reach" is indicated. This suggests that
[exec] Generated code coverage data to /data/data/blabla.project/files/coverage.ec
nine). In this matter. Protection is not relevant data. This is a length of 37 bytes. The report says that
processing input file [/home/ubuntu/projects/ppf2/workspace/PPF2/tests/coverage.ec] ... loaded 0 coverage data entries ... no collected coverage data found in any of the data files [all reports will be empty]
Everything seems good to me except the last step.