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. Beginning of Clover 4.1 release, we will remove all documentation related to Clover for Android prototype and close the related issues.
New to Clover?
If you haven't used Clover before, we strongly recommend spending few minutes to learn its basic features:
A prototype has been tested using following software versions, but it should work on other versions as well.
Note: Clover-for-Android is based on the Clover-for-Eclipse 3.1.7.
Note: Clover-for-Android is using 'adb' application to fetch coverage data from a device. It expects to find it in:
Please note that location of 'adb' has changed from <sdk>/tools to <sdk>/platform-tools since SDK v 8, so please don't use older SDK versions. Value of <sdk> is being fetched from 'com.android.ide.eclipse.adt.sdk' property in Eclipse Preferences ("Window > Preferences > Android > Android SDK").
Note: Clover-for-Android has been tested on a following configuration:
Clover for Android has following differences, compared to base Clover for Eclipse:
A following features were not tested on Clover for Android:
A following features do not work currently:
1) Run Eclipse and open your Android project.
2) Right click on the project, select "Clover > Enable on this project" from context menu.
3) Right click on the project, select "Properties > Clover". Toggle on "Enable Clover in this project". Next select "Custom value" radio button and enter a path to Clover database in a following format:
clover+remote:file:///<path to database file on desktop>?localCoverageDir=<path to coverage directory on device>
Click OK. All Clover views shall be added to current perspective. You can also open them from "Window > Show view > Other ... > Clover".
Possible InitString formats:
Keep in mind that for URIs:
: = %3A
\ = %5C
Examples:
4) Change the flush policy to "At set intervals from a Clover thread" or "At set intervals" and define interval (1000 ms for example).
Note that when you close application on Android device, JVM is still running, thus the "At JVM shutdown ..." option is not preferred.
You can also trigger Clover flush programaticaly - just put "///CLOVER:FLUSH" inline comment in your code (for example in Activity.onDestroy() method).
5) Open "Project Properties > Java Build Path > Order and Export". You will find a CLOVER_RUNTIME library on a list. Enable the checkbox so that Clover library will be exported. Perform a full rebuild of the project. You should see "red coverage" in source files and in Coverage Explorer.
1) Select "Run as ... > Android application" from main menu or Package Explorer context menu. You can execute your application or unit tests on a real device or simulator. Choose device you wish to use.
There is no need to copy the clover.db to a device (yay!). Clover-for-Android is using a special coverage recorder version, which does not require presence of this database.
There is also no need to copy clover.jar to a device (yay!). Google Android Toolkit will automatically package CLOVER_RUNTIME jar file into Dalvik image during packaging.
Option #1
Unit tests for Android are kept in a separate Eclipse project.
For such scenario we have found a following configuration which works:
Right click on the test project and select "Run as ... > Android JUnit Test". After tests are finished, select both projects in "Coverage Explorer" view and click "Refresh Coverage Data" button for each of them.
You shall see coverage results for both projects.
Option #2
Unit tests are kept together with application code in one Eclipse project.
Configuration not tested yet.
Just click on the "Refresh Coverage Data" button
Clover is using "adb" command to retrieve coverage files from the default device. Make sure that you're running one device only, otherwise you might fetch coverage snapshots from wrong device.
As soon coverage data is fetched from device you can browse them using Coverage Explorer or Test Run Explorer view. It is also possible to generate HTML/XML/PDF reports, as usual.
When you click on the "Delete Coverage Recordings", Clover will remove files from desktop as well as from android device.
Clover is deleting coverage files from a location defined in initstring. In case when initstring has changed, you have to remove files manually - open the "File Explorer" view from "DDMS" perspective and navigate to a directory where coverage data was stored (usually it will be /data/data/com.my.application.name/clover).
Clover is using "adb" command to delete coverage files from the default device. Make sure that you're running one device only, otherwise you might delete coverage snapshots from wrong device.
Open "File > New ... > Project ... > Android > Android Sample Project" and click "Next". Choose "Android 2.3.3" build target and click "Next". Choose "Notepad" sample, name it "NotePad" and click Finish.
Right click on the project, select "Clover > Enable on this project" from context menu. All Clover views shall be added to current perspective. You can also open them from "Window > Show view > Other ... > Clover".
Open "Project Properties > Java Build Path > Order and Export". You will find a CLOVER_RUNTIME on a list. Tick the checkbox so that library will be exported.
Open "Project Properties > Clover". Set "clover+remote:file:///c%3A%5CTemp%5Candroid.db?localCoverageDir=/data/data/com.example.android.notepad/clover" initstring. Disable "Relative to project dir" checkbox. Set flush policy to "At set intervals from a Clover thread" with 1000 ms interval. Click OK.
Perform full rebuild. You should see red coverage in Coverage Explorer and text editors as on picture below.
Now let's run the application on Android device. Right click on the project, select "Run as > Android application". Wait few minutes until emulator starts and installs our app.
Add new notes, delete it, change title etc. Exit application.
Click "Refresh Coverage Data" button in Coverage Explorer view. After few seconds you shall see coverage data like on picture below:
You can browse coverage in IDE as well as generate XML/PDF/HTML reports, for example:
Prerequisite: "NotePad" project configured as in Example 1.
Open "File > New ... > Project ... > Android > Android Sample Project" and click "Next". Choose "Android 2.3.3" build target and click "Next". Choose "Notepad > tests" sample, name it "NotePadTests" and click Finish.
Right click on the NotePadTests project in Package Explorer. Open "Project Properties > Java Build Path > Projects". Add "NotePad" project to the list.
Click on the "Order and Export" tab, select NotePad checkbox. Click OK.
Open "Project Properties > Clover". Select "Enable Clover in this project" checkbox.
Set "clover+remote:file:///c%3A%5CTemp%5Candroid-tests.db?localCoverageDir=/data/data/com.example.android.notepad/clover" initstring. Disable "Relative to project dir" checkbox.
Set flush policy to "At JVM shutdown and on special instruction". Click OK and close Properties window.
Note that there is no need to export CLOVER_RUNTIME library, because it's already exported in the NotePad project.
Open NotePadTest class and add a tearDown() method like below:
public void tearDown() throws Exception { ///CLOVER:FLUSH super.tearDown(); }
Open NotePad/AndroidManifest.xml file and increase required API Level to 8 (it's required by ActivityInstrumentationTestCase2):
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
Perform full rebuild.
Right click on the NotePadTest project, select "Run as ... > Android JUnit Test" from context menu. Wait until tests are finished.
Select NotePad and NotePadTests project in Coverage Explorer and for each of them click on the "Refresh Coverage Data" button.
After few seconds you shall see coverage results similar to those:
In case of problems, you can search for more information in following places:
Open "Window > Preferences > Clover". Set "Clover plugin logging output level" to Debug or Verbose. Open Error Log console ("Window > Show view > Error Log"). You can track Clover messages like:
Executing 'D:\Soft\Android\android-sdk\platform-tools\adb.exe pull /data/data/com.example.android.notepad/clover/android-test.dbh3wa8ogtz4si_0_hut67c_h7aira7g.s c:\Temp\android-test.dbh3wa8ogtz4si_0_hut67c_h7aira7g.s'
deleting out of date coverage recording file: android-test.dbhut67c_h7air9v5, timestamp < 1348064838148
Read header for "c:\Temp\android-test.dbhut7iw_h7aj0xtu": Header[dbVersion=1348064838148, writeTimeStamp=1348064886310, format=0]
Recording data for file "c:\Temp\android-test.dbh4ffemvct3pe_0_hut7iw_h7aj0y4l.s": PerTestRecordingTranscript[coverage.size=64, testTypeName='com.example.android.notepad.NotePadTest', testMethodName='com.example.android.notepad.NotePadTest.testActivityTestCaseSetUpProperly', exitMessage='null', stackTrace='null', exitStatus='Normal', start=1348064884677]
Open "Window > Open perspective > DDMS".
We are waiting for your feedback! Feel free to vote on implementing full Android support in:
- CLOV-569Getting issue details... STATUS Clover for Ant
- CLOV-570Getting issue details... STATUS Clover for Maven 2&3
- CLOV-1122Getting issue details... STATUS Clover for Eclipse
- CLOV-1127Getting issue details... STATUS Clover for IDEA
- CLOV-1126Getting issue details... STATUS Clover Commandline Tools