It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Bharat Mistry Feb 08, 2016

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

0 votes
Answer accepted
Marek Parfianowicz Atlassian Team Feb 08, 2016

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

7,938 views 23 36
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you