
Clover is a great tool for generating code coverage reports from your unit tests. It can be executed as a plugin in Eclipse, Maven or Ant.
However, not everyone knows that it can also be used to collect coverage data of integration tests.
This post explains how to collect coverage data with clover at runtime.
This post assumes that you already know what are unit and integration tests.
This post assumes that you know what Clover is, and already used it either with Eclipse, Ant or Maven.
*Let me assured you that even though the directions bellow seems complicated and clumsy at first, after doing them once or twice it is really easy to repeat them.
Motivation
The default action of Clover is to gather code coverage information during build time or compile time. Therefore, This information includes just the coverage data created by unit tests.
If you are developing web applications, you probably use more technologies to test your applications beside unit tests. These technologies may include HTTPUnit/HTMLUnit or automation technologies (like Selenium). These technologies do not work at build time, they can only work during run time, where a web server is up and running and HTTP calls are made.
As a result, the code coverage made during build time is not reflecting the actual code coverage. We should be able to test the coverage while a server is running.
The idea
The idea is that we will first run clover regularly during build time. We will than take the clover artifacts, put them in our server and then run the integration tests.
While running the integration tests, the clover database will be updated and we would be able to generate reports from it which will reflect both unit and integration tests.
Step 1 – Preparation
- Make sure that you have a web/application server (Tomcat/JBoss/weblogic…) with your web application already deployed.
- Execute clover on your application as you would normally do (either by compiling the code on eclipse or by building with Maven or Ant, it doesn’t matter).
The result of this action would be:- Clover DB files.
One of the outcome of executing the clover on your code are the DB files.
The DB files hold all the information about your code and the coverage itself.The location of those files may change depending on the way you use clover and according to the way you configured clover in your environment.
This is how the files looks like

the .db file holds the information regarding your code (classes, methods and so on). All the other files hold all the coverage data.
It is important that you will locate those files because we are going to use them in the next step.
- An instrumented code.
Another outcome of clover is that it instruments your code. A clover call is injected into each method so it would be reported in the coverage calculation.
We will need this code. we will use this instrumented code in runtime to update the coverage data.If you use Eclipse than the generated classes would be instrumented. If you use Maven or Ant than most chances are that a jar with all the instrumented code would be generated separately.
Search the instrument code jar. Again, I can’t tell you exactly where it is located, but usually it generates a jar with a ‘clover’ postfix. Example: if your jar name is my_app.jar, than the generated instrumented code jar will probably be something like my_app-clover.jar.
So you will need to do some detective work here to find the instrumented classes/jar. If you are not sure whether the classes are instrumented or not, just decompile one of them with Jad and search for the word clover inside of it. - A code coverage report.
This is a report with the unit test coverage. We don’t really need this, but it would be good so that we would be able to compare it with the report we will generate at the end.
- Clover DB files.
Step 2 – Updating the server
The next steps are very important, please make sure you do them properly.
- Replacing the existing application jar/classes with the instrumented jar/classes.
Take the instrumented jar/classes that were created by the clover and add it to your server’s classpath instead of the original jar/classes.
The instrumented code will cause the clover DB to be updated with the runtime data. - Adding clover jars and license.
Since we will use clover on runtime we will need also the clover jars in our server’s classpath.
So add the clover own jars to your server’s classpath. If you are using clover with Eclipse than these jars are located in the plugin folder of Eclipse. If you are using Maven than they will be loacted in your repository.* Make sure you are using the same version of clover in your server as you used to generate the DB files and instrumented code, otherwise it will not work and you will get error messages.
Also add the clover license file to the same location as the jars. - Adding the clover java argument.
Add the following java arg -Dclover.initstring.basedir={location of the db files that were created by the clover}.
*Notice – the path you have entered above is the path of the folder which contains the DB files.
Example:
-Dclover.initstring.basedir=C:/workspace/MyWebApp/target/clover.
This java argument is used by the clover to locate the DB files and update them.
Step 3 – Restarting the server and running the tests
Now that hopefully all is set properly all that you need to do now is to restart your server and than running your integration tests.
The tests should trigger the instrumented code which will call the clover API’s and will update the clover DB.
-
While running the tests:
- Look at your log/console and search for error messages from clover.
- Look at the folder which holds the clover DB files. If everything is going as it should, new files will be created in this folder while running the tests.
If not everything is going well the first time, don’t discourage, just go over each of the steps again.
Step 4 – Generating an updated report
If everything went well and new files were created in the DB folder than that means you just need to generate a new report.
If you are using clover with eclipse than you can simply push the reload button
to reload the coverage data.
If you are using Maven or Ant you can execute just the task which generates the report.
Another way is to use the clover HtmlReporter to generate a report easily.
Now compare the new report to the old report. You should see that the new report coverage is much bigger than the old one since it contains also the integration tests coverage.
*Notice that not all the data is updated, even though the percentages are being updated, for some reason the calls counter does not.
To summarize. As mentioned; yes, these instructions seems a bit complicated but after you succeed the first time, it is very easy to repeat it. In the company I work for we even made this whole process automatic and we are able to generate a full coverage report with unit and integrated tests combined.

![]() |
Android developers web site provide you with 2 predefined animation techniques which you can use in your applications – Tween animation and frame animation. They are super easy to implement and work quite nice. If you are using Android 3.0 or above, you should check out Property Animation technicqe. |
|
| But what if you need to create your own customized animations and you are using older versions? Don’t worry, that is easy to do as well, here is how you do it. | ||
To create a customized animation you need to follow these 3 steps.
For the explanation, we will create a simple animation that changes the background of a button gradually from black to red.
Step 1 – Extend the Animation class and set the properties
Create a class which extends Android Animation class.
This class will hold the logic of your animation.
See my example:
public class BGColorAnimation extends Animation {
private View view;
private int currentRedColor;
//The steps to skip between colors
private static int STEP_SIZE=30;
private static int ANIMATION_DURATION=50;
public BGColorAnimation(View view) {
this.view=view;
setDuration(ANIMATION_DURATION);
setRepeatCount(255/STEP_SIZE);
setFillAfter(true);
setInterpolator(new AccelerateInterpolator());
setAnimationListener(new MyAnimationListener());
}
}
- As you see, there is not much in this class since my animation is not that complicated.
- Notice that I have made all the necessary animation parameters initialization from inside the constructor, but you can defiantly initialize them from outside the class.
- There are 2 important parameters which determines the behavior of the animation:
- RepeatCount – the number of steps this animation has.
- Duration – the sleep time between 2 steps.
- On each step, the animation listener will be triggered.
Step 2 – Implement AnimationListener interface
Create a class which implements Animation.AnimationListener.
As mentioned, it is triggered on each animation step.
class MyNumbersAnimationListener implements AnimationListener{
private int index;
class MyAnimationListener implements AnimationListener{
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
// Change color of the view
view.setBackgroundColor(
Color.rgb(currentRedColor+=STEP_SIZE, 0, 0));
}
@Override
public void onAnimationStart(Animation animation) {
view.setBackgroundColor(Color.BLACK);
currentRedColor=0;
}
}
In fact, I see no reason why not doing both steps in the same class:
public class BGColorAnimation extends Animation implements
Animation.AnimationListener {
private View view;
private int currentRedColor;
// The steps to skip between colors
private static int STEP_SIZE= 30;
private static int ANIMATION_DURATION = 50;
public BGColorAnimation(View view) {
this.view = view;
setDuration(ANIMATION_DURATION);
setRepeatCount(255 / STEP_SIZE);
setFillAfter(true);
setInterpolator(new AccelerateInterpolator());
setAnimationListener(this);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
view.setBackgroundColor(
Color.rgb(currentRedColor += STEP_SIZE, 0, 0));
}
@Override
public void onAnimationStart(Animation animation) {
view.setBackgroundColor(Color.BLACK);
currentRedColor = 0;
}
}
Step 3 – Start the animation from a view
Animations are triggered from a view.
Example:
Button button = (Button)findViewById(R.id.b_colors);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
button.startAnimation(new BGColorAnimation(button));
}
});
Well it’s a well known fact that the java native function System.arraycopy() is a useful way to copy one array to another since it is native, but is that also the case for Android? And if so, how much more useful is it?
To answer these questions I have made a simple test and ran it as a java program on my PC and than as an Android activity.
Here is the test for the PC:
private static final int SIZE_OF_ARRAY = 10000000;
private static long time;
public static void main(String[] args) {
Integer [] sourceArray = new Integer[SIZE_OF_ARRAY];
Integer [] destinationArray = new Integer[SIZE_OF_ARRAY];
fillArray(sourceArray);
startBenchmark();
naiveCopy(sourceArray,destinationArray);
stopBenchmark();
startBenchmark();
System.arraycopy(sourceArray, 0, destinationArray, 0,
sourceArray.length);
stopBenchmark();
}
private static void naiveCopy(Integer [] src, Integer [] dst) {
for (int i = 0; i < src.length; i++) {
dst[i]=src[i];
}
}
private static void fillArray(Integer [] src) {
for (int i = 0; i < src.length; i++) {
src[i]=i;
}
}
private static void startBenchmark() {
time = System.currentTimeMillis();
}
private static void stopBenchmark() {
time = System.currentTimeMillis() - time;
System.out.println( "time="+time);
}
Here are the results while running it from my PC (java 7, 8GB memory, CPU intel i5):
Naive algorithm – 14 ms
System.arraycopy(); – 6 ms.
Arraycopy does the task in less than half of the time.
Now to use it on Android – here is the code:
public class ArrayCopyTestActivity extends Activity {
private static final int SIZE_OF_ARRAY = 1000000;
private long time;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Integer [] sourceArray = new Integer[SIZE_OF_ARRAY];
Integer [] dst = new Integer[SIZE_OF_ARRAY];
fillArray(sourceArray);
startBenchmark();
naiveCopy(sourceArray,dst);
stopBenchmark();
startBenchmark();
System.arraycopy(sourceArray, 0, dst, 0, sourceArray.length);
stopBenchmark();
}
private void naiveCopy(Integer [] src, Integer [] dst) {
for (int i = 0; i < src.length; i++) {
dst[i]=src[i];
}
}
private void fillArray(Integer [] src) {
for (int i = 0; i < src.length; i++) {
src[i]=i;
}
}
private void startBenchmark() {
time = System.currentTimeMillis();
}
private void stopBenchmark() {
time = System.currentTimeMillis() - time;
Log.d("array copy test", "time="+time);
}
}
* Notice I have reduced the size of the Array from 10 million to 1 million, this is due to restrictions on memory for applications in Android.
The results from running it on my device (nexus 1):
Naive algorithm – 182 ms
System.arraycopy(); – 12 ms.
This means that the fact that System.arraycopy() is better than the regular copy is even more true for Android.
In short than, always use System.arraycopy() especially on Android.


Recent Comments
Karol on Android – Multithreading in a UI environment
Hi All the examples I see so far implement the Runnable object as inner class of the main...Avi on How to use fiddler+firefox to download files from streaming sites.
Try searching "Mpeg layer-3" instead.ashi on How to use fiddler+firefox to download files from streaming sites.
hi, i tried above i downloaded fiddler2 and also the script editor... also pasted the code but but i have problem in step...Rui Pedrosa on Android – Multithreading in a UI environment
A simple but very useful explanation! thanks!Hui Sunray on Using Hibernate Validator to cover your validation needs
I like your examplesSridhar on Weekend project: Bluetooth multisender
Excellent work and it is sending to many bluetooth devicesjetti on Android Development – Preferences
Hi, How can I add Icon/Image to each item in ListPreference? Is it possible to add our own icons...Eric on Android – Multithreading in a UI environment
Thx, helped alot :)lilman on Memory Game – Android Application
hey i got the same problem with arrayAdapter.. how can i fix it? any suggestions?Renato on Memory Game – Android Application
Thanks Man !!