Emma reports coverage of 0%

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.

+2
source share
2 answers

Finally, after many hours of battle, the question was resolved. Resolution is very simple and non-obvious.

In the build.properties of the TEST project, I had something like:

 tested.project.dir=.. env.WORKSPACE= /bla/bla source.dir=${env.WORKSPACE}/first/src;${env.WORKSPACE}/second/src;${env.WORKSPACE}/andsoon/src; 

But! I should not indicate source.dir here! The tested.project.dir task tested.project.dir enough to successfully compile a test project.

Also, if I specify source.dir in a TEST project like this, the tests work fine, but emma reports zero coverage as indicated in the question.

0
source

I ran into the same problem and I think I understand what happened here.

It appears that the sources of the test package were also inside (or indicated as sources) of the test package.

As a result, your apks packages looked like this if you opened them :

 PackageUnderTest/ClassFileUnderTest TestPackage/TestClass TestPackage/ClassFileUnderTest 

ClassFileUnderTest:

 pluclic class ClassFileUnderTest{ public int foo(){ ... } } 

TestClass:

 pluclic class TestClass{ public void testFoo(){ int result = foo(); assert... } } 

What happens here is that whenever your TestClass called the foo () method from testFoo (), foo () was called in TestClass / ClassFileUnderTest instead of PackageUnderTest / ClassFileUnderTest.

As a result, the instumented PackageUnderTest / ClassFileUnderTest never started and was not calculated in the coverage report.

Removing the PackageUnderTest reference code from TestPackage forced the PackageUnderTest code to be run from PackageUnderTest and entered into the coverage report.

+3
source

All Articles