Use Clover to generate code coverage reports of your integration/automation tests

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 Continue reading Use Clover to generate code coverage reports of your integration/automation tests

Android development – Custom Animation

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: 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 Continue reading Android development – Custom Animation

Android quick tip: use System.arraycopy()

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: 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: * 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. Test for Continue reading Android quick tip: use System.arraycopy()

HtmlUnit – A quick introduction

HtmlUnit is an open source java library for creating HTTP calls which imitate the browser functionality. HtmlUnit is mostly used for integration testing upon Unit test frameworks such as JUnit or TestNG. This is done by requesting web pages and asserting the results. Simple Example WebClient As you can see in the example, the WebClient is the starting point. It is the browser simulator. WebClient.getPage() is just like typing an address in the browser. It returns an HtmlPage object. HtmlPage HtmlPage represents a single web page along with all of it’s client’s data (HTML, JavaScript, CSS …). The HtmlPage lets you access to many of a web page content: Page source You can receive the page source as text or as XML. HTML Elements HtmlPage lets you ability to access any of the page HTML elements and all of their attributes and sub elements. This includes tables, images, input fields, divs or any other Html element you may imagine. Use the function getHtmlElementById() to get any of the page elements. Anchors Anchor is the representation of the Html tag <a href=”…” >link</a>. Use the functions getAnchorByName(), getAnchorByHref() and getAnchorByText() to easily access any of the anchors in the page. Dom Continue reading HtmlUnit – A quick introduction