How do I get code coverage in Project A from running tests from Project B

I am new to clover and have an evaluation license.  I would like to have a code coverage report of code that is called by a user via REST API's.   The REST calls are made throught JUNIT and various supporting libaries for HTTP/JSON libaries etc.  I have tried various scenarious and have not been successfull in intrumenting the code and getting a reports.

The project structure is as follows


   --- Modules related to project     --- Project A     Src     Unit Tests        --- Project B (Tests executed via Rest Calls).     Src (no code here)     Test Src (all tests to be executed here)            --- Other projects   ---   ---  

When tests  a run a container is started and the war from Project A is placed in this container and then the tests are run.

I initially instrumented the code in Project A and then run the tests from project B.  When A report was generated I found that the results I had expected where not there.  Basically some methods that should have had a coverage report of lets say 80% and more had 0% percent.

I am not sure what I need to do to get  such a test working.

I had added the following section in the POM file and ran the command as mvn clover2:instrument. This created the relvent structure and files in Project A.

   <plugin>     <groupId>com.atlassian.maven.plugins</groupId>     <artifactId>maven-clover2-plugin</artifactId>     <version>4.0.6</version>     <configuration>      <licenseLocation>clover.license</licenseLocation>     </configuration>    </plugin>

 I would have expected that when I run project B  as follows  this would have generated updated the clover database files etc.    call mvn --log-file %LogFile% clean install -fae integration-test -PacceptTests (other JVM setting etc port number etc)    Then I ran clover2:clover in project A, expecting a full report, but got a report that did not relate to tests in Project B.  

1 answer

1 accepted

Accepted Answer
0 votes

1) You ran clover2:instrument which forks a parallel build life cycle. Thus, code instrumented by Clover gets packaged into JAR files with the "-clover" suffix. I suspect that the WAR you deployed contained non-instrumented code. Please try running "clover2:setup" instead, which will instrument code in a main build cycle. For instance: "mvn clean clover2:setup".

2) I'm not sure how did you define dependency between ProjectB and ProjectA and how do you launch in-container tests, but it's quite probably that the WAR is being picked from the ~/.m2/repository folder. Am I correct? If yes, then you shall also install code instrumented by Clover locally, e.g.: "mvn clean clover2:setup install".

3) You wrote that you ran "clover2:clover" goal to generate the report - in case your project has more than 1 module, you shall also merge databases from all modules before report generation - in order to have one consolidated report. Thus, call the "clover2:aggregate clover2:clover".

4) I see that you're using Clover 4.0.6. Please note that the latest version is Clover 4.1.1, in which the Maven plugin is named 'clover-maven-plugin' and goals have the "clover:" prefix (instead of "clover2:"). 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

289 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you