I want to know that can we run a war (or sar) file compiled with clover on jBoss and if we can, then does clover provide the facility to check the code coverage.
Say we compile an application with clover and deploy it on server. End users work this application and at the end of the day we want to check how much code was covered during this period. Can we do it?
If we can do it then please mention the configuration steps so that we can check the code coverage.
Please note that this question is from end user's perspective who is using the application and not from jUnit perspective.
Thanks,
Sumeet
Can anyone please provide a sample target clover.setup for instrumenting the code which is ready to use with tutorial project.
The build_completed.xml file in tutorial contains complete Clover configuration. Just type:
ant clover.all -Dtest.target=test.run
Hi Sumeet,
Yes, Clover can instrument WAR and SAR applications too. Typical steps are as follows:
References:
Cheers
Marek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<project name="money_demo" default="code.compile" basedir="."> <property name="src" location="src/main/java"/> <property name="test.src" location="src/test/java"/> <property name="app.build" location="build/app"/> <property name="test.build" location="build/test"/> <property name="test.result" location="build/testresult"/> <property name="junit.jar" location="lib/junit-3.8.2.jar"/> <property name="clover.jar" location="../lib/clover.jar"/> <taskdef resource="cloverlib.xml" classpath="${clover.jar}"/> <path id="build.classpath"> <pathelement path="${clover.jar}"/> <!-- I added this to make clover.jar avail in runtime --> <pathelement location="${junit.jar}"/> <pathelement location="${app.build}"/> </path> <path id="testbuild.classpath"> <path refid="build.classpath"/> <pathelement location="${test.build}"/> </path> <target name="-check.clover"> <available property="clover.installed" classname="com.cenqua.clover.CloverInstr" /> </target> <target name="guard.noclover" depends="-check.clover" unless="clover.installed"> <fail message="The target you are attempting to run requires Clover, which doesn't appear to be installed"/> </target> <target name="clover.report"> <clover-html-report outdir="clover_html" title="Clover Demo"/> </target> <target name="record.point"> <clover-historypoint historyDir="clover_history"/> </target> <target name="code.compile" description="Creates ${app.build} directory and compiles sources from ${src} to ${app.build}"> <mkdir dir="${app.build}"/> <javac includeantruntime="false" srcdir="${src}" destdir="${app.build}" classpathref="build.classpath" source="1.4"/> </target> <target name="test.compile" depends="code.compile" description="Creates ${test.build} directory and compiles sources from ${test.src} to ${test.build}"> <mkdir dir="${test.build}"/> <javac includeantruntime="false" srcdir="${test.src}" destdir="${test.build}" classpathref="testbuild.classpath" source="1.5"/> </target> <target name="test.run" depends="test.compile" description="Runs the tests"> <mkdir dir="${test.result}"/> <junit fork="yes" printsummary="true" showoutput="true"> <classpath refid="testbuild.classpath"/> <formatter type="xml"/> <batchtest fork="yes" todir="${test.result}"> <fileset dir="${test.src}" includes="**/*Test.java"/> </batchtest> </junit> </target> <target name="clean"> <delete dir="build"/> <clover-clean/> <!-- I added this to delete clover database when clean target is executed --> </target> <target name="with.clover"> <clover-setup/> </target> <target name="hist.report"> <clover-report> <historical outfile="historical.pdf" historyDir="clover_history"> <format type="pdf"/> </historical> </clover-report> </target> <target name="clover.check" depends="with.clover"> <clover-check target="80%"/> </target> <target name="clover.setup" if="clover.enabled"> <mkdir dir="${clover.db.dir}" /> <mkdir dir="${clover.instr.dir}" /> <clover-instr initString="${clover.db.dir}/coverage.db" destdir="${clover.instr.dir}"> <fileset dir="${src}" /> <testsources dir="${tests}" /> </clover-instr> <echo> Clover is enabled and will be used for generating test reports </echo> </target> </project>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<target name="clover.setup">
<echo>
Clover is enabled and will be used for generating test reports
</echo>
<mkdir dir="${clover.db.dir}" />
<mkdir dir="${clover.instr.dir}" />
<clover-instr initString="${clover.db.dir}/coverage.db" destdir="${clover.instr.dir}">
<fileset dir="${src}" />
<testsources dir="${tests}" />
</clover-instr>
<flushpolicy>threaded</flushpolicy>
</target>
Ran the ant build with a slight change in the clover.setup and this time the new directories were created but they are empty.
I was expecting instrumented classes in those directories but it is not.
Can anyone please provide a sample target clover.setup for instrumenting the code which is ready to use with tutorial project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The build.xml file defined by you contains both <clover-setup> and <clover-instr> tasks. Both tasks are making virtually the same - they instrument the code - but the difference is that <clover-instr> puts instrumented sources into a specified directory, while the <clover-setup> peforms instrumentation "on the fly", by intercepting the <javac> task.
It means that there is no need to have both tasks defined. I recommend using <clover-setup> only. Similarly the 'ant with.clover clover.setup' call was also incorrect, as no compilation (javac) was triggered.
Please try the following:
* remove <target name="clover.setup"> as it is obsolete
* run 'ant clean with.clover test.run clover.report' - it shold enable Clover, compile the code, run tests and generate an HTML report
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I am instrumenmting clover with war file using Ant. I see clover related jar and class files when I see war info. This ensures me that clover instrumented war is correct. I am trying to run soapUI tests and generate coverage files. I have corretcly set up path for clover.db in initstring. However, the coverage files are not generated when soapUI tests are run.
I did similar setup using maven and it worked flawlessly. What could be the issue with ant setup ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How do you run your soapUI tests exactly?
Do you deploy your application to some server or instantiate container on-the-fly?
If yes, then do you shutdown this sever after tests are finished? By default, Clover's coverage recorders will write coverage files to disk at the JVM shutdown (they attach to proper hook).
If not, then did you set the <clover-setup flushpolicy="treaded"> or <clover-setup flushpolicy="interval">? This will change the default flush policy and start writing coverage files periodically, so there's no need to shutdown JVM.
Do you see the clover.db.liverec file when running your tests? This indicates that at least one coverage recorder has started.
Do you see any Clover-related error messages when running your application? For instance, that the coverage recorder could not start because it did not find the database. This may indicate a problem with initstring. Using runtime property -Dclover.initstring=/path/to/clover.db may help.
Do you see any NoClassDefFound exceptions in the log? Especially the ones with classes from the com_cenqua_clover package? This may indicate that the clover.jar packaged into your WAR was not picked up by a class loader. In such case, putting clover.jar into application server's /lib directory should help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Marek. Thank you for your quick response.
I deploy the application war file to Glassfish server. Then I run my soapUI tests by giving the Glassfish server end point address in soapUI (ex: xyz.xx.xy.xz:8080/service).
Intially I noticed error in log files: clover database not found at specified path. Executing with -Dclover.initstring=/path/to/clover.db helped to solve this error.
I also added flushpolicy and flush interval attributes in <clover-setup>. Now I see permission denied error:
[#|2014-05-14T12:04:26.582-0400|SEVERE|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=817;_ThreadName=Thread-2;|ERROR: java.io.FileNotFoundException flushing coverage for recorder /home/user/workspace/cloverDB/clover.dbao50rb_hv6t1omy: /home/user/workspace/cloverDB/clover.dbao50rb_hv6t1omy (Permission denied)|#]
In above error, /home/user/workspace/cloverDB/ is the path I specified in initstring, where clover.db present.
I tried changing permission of clover.db, but it didnt help.
Clover did produce the coverage files when I did not use flush policy and stopped the server. So I think my problem was with clover.db path when initially it did not generate files.
Thank you for all your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you also change a permission for the directory:
/home/user/workspace/cloverDB/
to allow Glassfish to create new files in it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.