Specify source directory in clover config

Tushar Bhasme September 3, 2015

We have a separate project for source and test. Also, the source files lie directly under src/ instead of src/main/java. The clover shows 0 coverage for these projects. Is there any setup we can do to make clover produce a correct coverage?

8 answers

0 votes
Tushar Bhasme September 10, 2015

Thanks a lot guys to locate the issue. I followed the steps specified in the link and facing some issues:

  1. We are not using tycho-compiler-plugin. Does it need to be configured for workaround to work? We do use tycho-surefire-plugin which I have configured as specified in the link.
  2. On executing  mvn -X clover2:instrument -DcloverOutputDirectory=../proj_instr, I am getting error 

    [ERROR] Failed to execute goal org.eclipse.tycho:tycho-packaging-plugin:0.16.0:package-feature (default-package-feature) on project com.abc.labs.proj.scan.feature: Execution default-package-feature of goal org.eclipse.tycho:tycho-packaging-plugin:0.16.0:package-feature failed: com.abc.sys:com.abc.labs.proj.scan:eclipse-plugin:2.3.0-SNAPSHOT does not provide an artifact with classifier 'null' -> [Help 1]

     

    I am not able to understand this error. Is this error due to some missing configuration in project or tycho or clover?

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 9, 2015

You can't use Clover with Tycho plugin in a standard way. The problem is that Tycho plugin ignores Maven's source roots. More details here:

https://confluence.atlassian.com/display/CLOVER/Using+Clover+with+Maven+Tycho+Plugin

0 votes
Tushar Bhasme September 8, 2015
Thanks for the analysis. Here are the answers:
  1. These are eclipse rcp projects. There are separate projects each for source code and their tests. They don't follow the generic convention of directory hierarchy src|test/com/java. Instead, both source and tests in their own project lie directory under src/. These are simple Junit tests.
  2. proj-app contains all the modules, under which proj-parent and project-test-parent act as parents to all other projects. 

    proj-app
    	- proj-parent (parent to all non-.tests projects) (has a tycho atrifact as a parent)
    	- proj-test-parent (parent to all .tests projects) (has proj-parent as parent)

    Clover is configured in proj-parent.

  3. The metric for the project com.abc.labs.proj.rules.tests is

    <metrics conditionals="26" methods="13" classes="1" files="1" packages="1" coveredstatements="0" complexity="26" loc="314" ncloc="255" coveredmethods="0" coveredconditionals="0" statements="128" coveredelements="0" elements="167"/>

    The metric for the 6 packages are:

    <metrics classes="1" methods="13" conditionals="26" files="1" ncloc="255" coveredstatements="0" coveredmethods="0" complexity="26" coveredconditionals="0" statements="128" loc="314" coveredelements="0" elements="167"/>
    <metrics classes="38" methods="102" conditionals="6" files="38" ncloc="1562" coveredstatements="0" coveredmethods="0" complexity="105" coveredconditionals="0" statements="711" loc="2009" coveredelements="0" elements="819"/>
     
    <metrics classes="1" methods="6" conditionals="6" files="1" ncloc="85" coveredstatements="0" coveredmethods="0" complexity="10" coveredconditionals="0" statements="47" loc="114" coveredelements="0" elements="59"/>
     
    <metrics classes="1" methods="3" conditionals="0" files="1" ncloc="39" coveredstatements="0" coveredmethods="0" complexity="3" coveredconditionals="0" statements="12" loc="48" coveredelements="0" elements="15"/>
     
    <metrics classes="4" methods="24" conditionals="56" files="3" ncloc="452" coveredstatements="0" coveredmethods="0" complexity="60" coveredconditionals="0" statements="225" loc="635" coveredelements="0" elements="305"/>
     
    <metrics classes="1" methods="19" conditionals="0" files="1" ncloc="190" coveredstatements="0" coveredmethods="0" complexity="19" coveredconditionals="0" statements="128" loc="250" coveredelements="0" elements="147"/>
     
    <metrics classes="3" methods="5" conditionals="0" files="3" ncloc="157" coveredstatements="0" coveredmethods="0" complexity="5" coveredconditionals="0" statements="107" loc="211" coveredelements="0" elements="112"/>

    The first two metrics are for the same package but shown twice by clover. That package in all has 39 files. There seems to be an issue since the project metric here shows packages=1 while it actually has 6.

  4. The metric for the project com.abc.labs.proj.rules is

    <metrics conditionals="1222" methods="771" classes="149" files="133" packages="20" coveredstatements="0" complexity="1425" loc="8621" ncloc="6734" coveredmethods="0" coveredconditionals="0" statements="2890" coveredelements="0" elements="4883"/>
  5. There exists a file named clover.db in D:\GitHub\repos\proj-app\com.abc.labs.proj.rules\target\clover

  6. There exists a file named clover.db in D:\GitHub\repos\proj-app\com.abc.labs.proj.rules.test\target\clover

0 votes
Grzegorz Lewandowski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 8, 2015

Hi, 

I've looked at the logs. And it seems that sources for both com.abc.labs.proj.rules and com.abc.labs.proj.rules.tests modules are getting instrumented by Clover:

[INFO] ------------------------------------------------------------------------
[INFO] Building com.abc.labs.proj.rules 2.3.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ com.abc.labs.proj.rules ---
[INFO] Deleting D:\GitHub\repos\proj-app\com.abc.labs.proj.rules\target
...
[INFO] Creating new database at 'D:\GitHub\repos\proj-app\com.abc.labs.proj.rules\target\clover\clover.db'.
[INFO] Processing files at 1.7 source level.
[INFO] Clover all over. Instrumented 133 files (20 packages).
[INFO] Elapsed time = 3.593 secs. (37.016 files/sec, 2,399.388 srclines/sec)
...
 
[INFO] Building com.abc.labs.proj.rules.tests 2.3.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
[INFO] Creating new database at 'D:\GitHub\repos\proj-app\com.abc.labs.proj.rules.tests\target\clover\clover.db'.
[INFO] Processing files at 1.7 source level.
[INFO] Clover all over. Instrumented 48 files (6 packages).
[INFO] 97 test methods detected.
[INFO] Elapsed time = 1.491 secs. (32.193 files/sec, 2,401.744 srclines/sec)

I have couple of additional questions for you

 

  1. Could you tell more how you organize the tests and against what exactly they are being run? Are those simple JUnit tests or something else?
  2. Could you tell me more how you configure Clover, in which maven module did you put the configuration? The project itself contains one root project with multiple submodules or is the structure more complex? 
  3. Could you confirm that report written to the D:\GitHub\repos\proj-app\com.abc.labs.proj.rules.tests\target\site\clover\clover.xml file shows 0% coverage?
  4. Could you confirm that report written to the D:\GitHub\repos\proj-app\com.abc.labs.proj.rules\target\site\clover/clover.xml file shows 0% coverage?
  5. Could you confirm existence of coverage files (named clover.dbHEXNUMBER) in the D:\GitHub\repos\proj-app\com.abc.labs.proj.rules\target\clover directory?
  6. Could you confirm existence of coverage files (named clover.dbHEXNUMBER) in the D:\GitHub\repos\proj-app\com.abc.labs.proj.rules.test\target\clover directory?
  7. Could you execute maven with -X switch in order to get more detailed logs and attach the output?

 

Best regards

Grzegorz Lewandowski

0 votes
Tushar Bhasme September 8, 2015

Attaching the complete log, we can discuss about com.abc.labs.proj.rules project, tests for which lie under com.abc.labs.proj.rules.tests, both having code under src/

Command ran:  mvn clean clover2:setup test clover2:aggregate clover2:clover -P clover

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 7, 2015

Could you please tell what Maven command did you run? If you see your classes in the HTML report then it means that code was successfully instrumented by Clover. Having no 0% coverage means that no coverage recording files were produced (or found).

Possible causes:

  • no tests were executed (e.g. running 'mvn clover2:setup compile ...' instead of 'mvn clover2:setup test ...'
  • non-instrumented classes were taken for execution (for instance an xyz-N.N.N.war instead of xyz-N.N.N-clover.war was deployed)
  • clover.db was not found while running tests (e.g. due to a different working directory used for test execution; or execution on another machine)

... but I would have to see build logs to tell what went wrong.

0 votes
Tushar Bhasme September 7, 2015

OK, so I did that but clover still shows me 0 code coverage for those projects. Is there any requirement to keep both source and test files under the same project?

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 4, 2015

You can use build-helper-maven-plugin:add-source/add-test-source to specify app/test source folders. Note that these goals shall be called before calling the clover2:setup goal. You can achieve this by binding them to different build phases in your pom.xml.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events