Add a emma profile to the project that we want to measure:
<build/>
<!-- un-commment when you want use sonar to present rules
<properties>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.emma.reportPath>target/emma/</sonar.emma.reportPath>
<sonar.surefire.reportsPath >../regalandroid-test/target/surefire-reports</sonar.surefire.reportsPath>
<sonar.core.codeCoveragePlugin>emma</sonar.core.codeCoveragePlugin>
</properties>
-->
<profiles>
<profile>
<id>emma</id>
<build>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<emma>
<enable>true</enable>
<classFolders>${project.basedir}/target/classes/</classFolders>
<outputMetaFile>${project.basedir}/target/emma/coverage.em</outputMetaFile>
</emma>
<dex>
<noLocals>true</noLocals> <!-- must be set for emma -->
</dex>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
emma.enable = true = run emma instrumentation, modify compiled class by putting emma code to classes.
emma.classFolders = folder where are compiled classes.
emma.outputMetaFile = coverage.em - emma meta data file ( need for generating rapport - because of emma4it plugin the best place folder for this file is target/emma/ folder.
Important:
dex.noLocals - this need to be set for emma.
To run emma instrumentation:
This command will compile code with emma instrumentation.
Add the following to the pom file of the the test project:
<build/>
<profiles>
<profile>
<id>emma</id>
<dependencies>
<dependency>
<groupId>emma</groupId>
<artifactId>emma</artifactId>
<version>2.1.5320</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<!-- read project properties ( can be build.properties or default.properties
Most important property is tested.project.dir - should be path to project which we want measure coverage
-->
<file>project.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<test>
<!-- Run test with flag "-w coverage true" this is need for generate coverage.ec file, result file-->
<coverage>true</coverage>
<createReport>true</createReport>
</test>
</configuration>
<extensions>true</extensions>
<!-- need for pull coverage.ec file and move to tested project-->
<executions>
<execution>
<id>pull-coverage</id>
<phase>post-integration-test</phase>
<goals>
<goal>pull</goal>
</goals>
<configuration>
<pullSource>/data/data/com.example.android.apis/files/coverage.ec</pullSource>
<pullDestination>${tested.project.dir}/target/emma/coverage.ec</pullDestination>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<!-- Plugin for generate report - if you want use sonar you could skip this raport plugin -->
<groupId>org.sonatype.maven.plugin</groupId>
<artifactId>emma4it-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<metadatas>${tested.project.dir}/target/emma/coverage.em,${tested.project.dir}/src/</metadatas>
<instrumentations>${tested.project.dir}/target/emma/coverage.ec</instrumentations>
<reportDirectory>${tested.project.dir}/target/emma/</reportDirectory>
<baseDirectory>${tested.project.dir}/target/</baseDirectory>
<formats>xml,html</formats>
</configuration>
</plugin>
</plugins>
</reporting>
</profile>
</profiles>
To run emma instrumentation and measure test coverage:
This command will compile code with emma instrumentation and run integration tests with
flag "-w coverage true" and generate coverage.ec file
and pull coverage.ec file to ${tested.project.dir}/target/emma/
When all tests are successful finished we should have in folder:
${tested.project.dir}/target/emma/
coverage.em file ( around more then 1MB)
coverage.ec file ( more then 37B ) 37B = empty file
When we have this two files we can generate report (sonar or report plugin)