Imagine a multi-modules Maven project, such as the following one:
parent
+- core
+- main
main
is dependent on the core
module.
I now write a class CoreClass
in core
, with 2 methods: method1()
and method2()
.
In core
tests, I write a test class that will only test CoreClass.method1()
.
If I run a coverage tool (in my case Cobertura, using mvn sonar:sonar
), I will find that I get 50% of test coverage on CoreClass
(if we imagine that both methods have the same length).
Until now, everything is ok.
Now, in main
project, I write a test class that will test the CoreClass.method2()
. So normally, I would expect to have 100% of line coverage on CoreClass
when I run an analysis on the whole project.
However, I still get my 50%.
I understand that this is a comprehensive behavior. Indeed, Cobertura will instrument CoreClass
for coverage analysis only during the tests execution on the core
module, and not on the main
.
That explains why I still have 50% of code coverage.
However, my question is to know if there is a way to get the real code coverage of CoreClass
when I am running the tests on all of my modules.
Thanks!
ps: I know that in a perfect world, it is not the concern of the main
module to test the core
classes. But as you may know, we are not in a perfect world :o)
Technical information: Java 1.6, JUnit 4.8.1, Maven 2.0.9 (will be upgraded to 2.2.1 soon, but I don't think it does really matter), Sonar 2.8