This manual presents how to configure Clover in order to get code coverage for web applications - and this issue can actually split into several problem areas:
By default, Clover dumps coverage data at JVM shutdown. In case when your application sever is never shut down, you have to change the flush policy during instrumentation and use the "interval" or "threaded" option. See:
Clover requires permissions to read and write files on disk, read properties, register to JVM shutdown hook. It can happen that your application container has security restrictions applied and you have to grant Clover necessary permissions. See:
In case when:
then your project must be configured with a distributed coverage option. See:
GWT performs translation from Java to JavaScript of a client-side code. In this case Clover shall either instrument server-side code only or GWT application shall be executed in a sandbox. See:
Depends on whether your build is running tests in 'test' and/or 'integration-test' phase as well as is using maven-surefire-plugin and/or maven-failsafe-plugin, Clover configuration may vary a little. See:
Get sources from Bitbucket: https://bitbucket.org/atlassian/maven-clover2-plugin, next go to src/it/webapp.
It' a simple web application with two servlets named MyServlet and RemoteServlet and a one JSP page. Maven during integration test phase runs unit test which calls servlets locally (by instantiating them) or remotely (in container).
A project build has been configured with a distributed coverage feature in such way that the "Server" (i.e. the JVM where JUnits are launched) will wait until at least one "Client" (i.e. the JVM where business code is executed; in our case inside a Tomcat container) connects to it. Because of fact that our servlet classes will not be loaded by Tomcat class loader until first HTTP request comes, an extra MyServletContextListener class was created. This class does virtually nothing, but due to fact that it's being loaded by class loader during application deployment, the Clover initialization code bundled into this class will run and connect to "Server" on a specified port. As soon as connection is established, "Server" will start execution of unit tests.