Clover-for-Android
It's always hard for us to say no to our customers. However, design decisions are not only about "Do we want to have this feature?" but also "Is this a best feature we can implement using our available resources?". We want to invest our time in making your lives (and code!) better. The fact that Google are building their Android IDE based on IntelliJ IDEA, which has a built-in coverage tool, means that you can measure code coverage for your Android apps, in an environment supported by Google. Therefore, we decided to not implement Clover for Android in the near future.
The following article is a rough guideline how you could "hack" Clover to run on Android. Please keep in mind that Atlassian does not provide technical support for Android. See Supported Platforms.
Integration steps
Download:
- com.atlassian.clover:clover artifact from Maven (version 4.0.6 or higher)
- com.atlassian.clover:clover-runtime artifact (version 4.0.6 or higher)
Integrate with your build scripts:
- Bundle com.atlassian.clover:clover-runtime artifact into your application. Do not use com.atlassian.clover:clover - this is because of the 64k method limit on Dalvik VM - the 'clover' artifact (about 15 MB) is too large.
- Instrument your java sources using Clover - for instance call <clover-instr> Ant task or the CloverInstr command line tool (these classes are available in 'clover' artifact)
- Use the same path for clover.db on your development machine and on android device/emulator - typical location for data files is /data/data/<application_id>/; it also means that you shall use Linux or MacOS for development and not Windows (due to drive letters) to have the same path.
- Ensure that the location on device will be write-able
- Use an absolute path for initstring, e.g. "/data/data/<your_application_id>/clover.db"
- Set flush policy to "interval" and/or add "///CLOVER:FLUSH" comment on your application shutdown event - this is necessary because by default Clover writes coverage data to disk on JVM shutdown, which doesn't happen on Android.
- Compile these instrumented sources instead of the original ones and package the application
- Copy clover.db to /data/data/<your_application_id>... folder - you can use 'adb copy' command for this purpose; an alternative is to use the 'growable coverage recorder'
- Run the application and/or tests
- As soon as application terminates, copy coverage recording files back from the device - again, you can use 'adb ls' + 'adb copy' for this purpose
- Generate an HTML report using Clover database and coverage recording files from a developer machine
Hints
Manual testing
You can also force Clover to write coverage files to disk by putting ///CLOVER:FLUSH inline comment in your code, for example in an Activity.onDestroy() method.
Unit testing
You may need to add "CLOVER:FLUSH" directive in tear-down methods like below (in order to force writing coverage data to disk):
public void tearDown() throws Exception {
super.tearDown();
///CLOVER:FLUSH
}
Troubleshooting
The following features may not work on Android:
- Per-test coverage (when 'growable coverage recorder' is used)
- Test Optimization
- Distributed Coverage
Known bugs
- CLOV-1194 - Getting issue details... STATUS