In this article, we find out how to collect coverage data from a remote server. For this aim, we will use WebSphere as a server and Ant as a project builder, but you can use any other servers and builders.
Step 1
Run webserver with JaCoCo agent. For this add JVM flag //-javaagent//:
-javaagent:/opt/jacoco/jacocoagent.jar=output=tcpserver,address=*,port=10001
It needs to have path to jacocoagent.jar which you download from Jacoco site. You can find it in downloaded ZIP in lib folder.
It needs also port number. You can use any free port. This is a port on which Ant Jacoco Plugin will connect to download coverage data.
You can also add flag like this:
-javaagent:/opt/jacoco/jacocoagent.jar=destfile=jacoco.exec,output=file,append=false,classdumpdir=./classdump
but in this case you have to collect report file manually somehow. For our example we use first option.
Step 2
Create target into Ant build script:
<target name="get_data_from_remote_server">
<jacoco:dump address="${server_address}" port="10001" reset="true" append="false" destfile="${some_path}/jacocoResults/jacoco_remote.exec" />
</target>
where //address// — address of remote server, //destfile// — path where you want to save report.
Step 3
Modify building process. In general it should looks like:
- Build app
- Deploy app on server
- Start server
- Run system integration tests
- Collect all test reports
- Shut down server
Useful links