Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This <a href="https://thomassundberg.wordpress.com/2012/02/18/test-coverage-in-a-multi-module-maven-project/">recent blog post by Thomas Sundberg</a> contains a method that partially solves the issue by using ant for the cobertura calls, instead of using the maven cobertura plugin. </p> <p>It relies on the following basic approach with specialised pom.xml and build.xml files :</p> <p>Start with a typical maven compile on the parent pom, which will compile all classes in the child modules.</p> <pre><code>mvn clean compile # maven-compile-plugin called for compiling </code></pre> <p>Then instrument all of the module classes:</p> <pre><code>ant instrument # cobertura called for instrumentation </code></pre> <p>Then call the maven-surefire-plugin called for testing using the instrumented classes, with cobertura as a test dependency</p> <pre><code>mvn test </code></pre> <p>Then use a custom report call to pull in all of the results from different modules:</p> <pre><code>ant report # cobertura called for reporting </code></pre> <p>The key elements of the ant build.xml file are to instrument all modules separately and then to report on all of the modules after merging the results. This function needs to be called for each module in his example:</p> <pre><code>&lt;target name="instrumentAModule"&gt; &lt;property name="classes.dir" value="target/classes"/&gt; &lt;cobertura-instrument todir="./${module}/${classes.dir}"&gt; &lt;fileset dir="./${module}/target/classes"&gt; &lt;include name="**/*.class"/&gt; &lt;/fileset&gt; &lt;/cobertura-instrument&gt; &lt;/target&gt; </code></pre> <p>Then after the testing is complete, the reporting phase first merges all results from all of the different directories are merged into a new .ser file (called sum.ser in his example)</p> <pre><code>&lt;target name="report" depends="merge"&gt; &lt;property name="src.dir" value="src/main/java/"/&gt; &lt;cobertura-report datafile="sum.ser" format="html" destdir="./target/report"&gt; &lt;!-- Add all modules that should be included below --&gt; &lt;!-- fileset dir="./MODULE_NAME_TO_REPLACE/${src.dir}"/ --&gt; &lt;fileset dir="./product/${src.dir}"/&gt; &lt;/cobertura-report&gt; &lt;/target&gt; &lt;target name="merge"&gt; &lt;cobertura-merge datafile="sum.ser"&gt; &lt;fileset dir="."&gt; &lt;include name="**/cobertura.ser"/&gt; &lt;/fileset&gt; &lt;/cobertura-merge&gt; &lt;/target&gt; </code></pre> <p>It may be possible to integrate the ant components into maven using the antrun plugin, but I am not familiar enough with the phases/lifecycles to know where to put the different calls.</p> <p>This is very useful for me, as I write abstract test classes in my api modules and then provide them with an implementation in my lib modules. So far both cobertura and emma have been unable to handle this design so my code coverage is typically 0 or in the single digits.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload