this is the next what I would like to ask you, look we have two maven projects - DEV project and separately QA project, which is testing DEV codes (all the tests are located in QA project ), we do it using testNG.

So how can we compute code coverage in this particular case?

Shell we also instrument QA project codes? Or there should be different approach?

Please advise.

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

1) mvn clean - in order to ensure that old, non-instrumented classes will be removed (unless you have a dedicated build where code is always compiled with Clover enabled)

2) mvn clover2:setup compile or mvn clover2:setup test-compile - in order to enable Clover and to compile application and test classes

3) mvntest or mvn integration-test or mvn verify - in order to run your tests and record code coverage

4) mvn clover2:aggregate or mvn clover2:merge - in order to merge Clover databases (unless you use singleCloverDatabase=true option)

4) mvn clover2:clover - to generate Clover reports

All these goals can be run in a single mvn command. So typically it is:

mvn clean clover2:setup verify clover2:aggregate clover2:clover

You wrote that you call the "mvn clean install" (followed by mvn with Clover goals). May I ask you why do you call the "install" goal? It it because you need to install some artifacts for further testing?

You wrote that you have tests in a separate QA project. How does the QA project load code from a DEV project? I suppose that you have a following setup:

* first you run "mvn install" in DEV project to install DEV artifacts (JARs) into local ~/.m2 cache

* QA project has dependencies to DEV artifacts (JARs) in it's pom.xml, so

* next you run "mvn test" on QA and it fetches JARs from ~/.m2 and runs tests on them.

Is my guess correct?

Do you build DEV and QA projects on the same machine? Is it a dedicated machine for QA testing? Why am I asking? Well, because we may need to figure out how to pass DEV artifacts to QA, ensuring that:

* your QA will fetch instrumented DEV jars and not the normal ones and

* you will not accidentally install/deploy instrumented DEV jars in a location (directory/server/repostory...) where you expect to have non-instrumented jars only

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

before describing in more details my situation, I would like to make clear for me something. So my general understanding is that, if I have instrumented jar of project "A", then I can calculate coverage even by simply running some method of other project named "B", which just calls one of the methods of instrumented "A" project, (I mean there is no need to have junit tests or tests written using testng in project "B", in order to calculate coverage of "A")

Now let me describe in more details what I have done.

1. Created Dev maven project

2. run

mvn clean install

mvn clover2:clean clover2:instrument clover2:aggregate

3. As a result of step "2", I have instrumented jar in target folder also in local repo, also coverage.db file is created under .clover folder

4. Created QA maven project and include Dev project as a maven dependancy

5. Wrote method TestClass#test() in QA project which calls some method of Dev project

6. run method TestClass#test().

As a result of step "6" I expect that coverage.db should be filled somehow(method usage of Dev project will be recorded) and when I run mvn clover2:clover I would get the final report.

But instead of that, I am getting the follwoing exception

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.sevak.DevCode$__CLR3_3_000hwc3qt0q at com.sevak.DevCode.someFunc(DevCode.java:7) at com.sevak.TestClass.test(TestClass.java:7)

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

if I have instrumented jar of project "A", then I can calculate coverage even by simply running some method of other project named "B"

Indeed. As soon as code in project A is instrumented, it will record code coverage, no matter whether the project B has been instrumented or not.

3. As a result of step "2", I have instrumented jar in target folder also in local repo, also coverage.db file is created under .clover folder

4. Created QA maven project and include Dev project as a maven dependancy

Because of the fact that you're using clover2:instrument goal, Clover forks a parallel build life cycle and all artifacts produced have the -clover.jar suffix. Can you confirm that you QA project has a dependency to DEV project with a <classifier>clover</classifier>?

But instead of that, I am getting the follwoing exception:Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.sevak.DevCode$__CLR3_3_000hwc3qt0q

The "NoClassDefFoundError ...SomeClass$__CLR..." means that JVM was unable to load a class instrumented by Clover. It means that you don't have a clover.jar on your class path in the QA project.

As I describe in my last comment step #6 - run method TestClass#test() from QA project

Here I expect that the method call should be recorded in .clover/coverage.db,

but in fact it does not, since in step #7- when I run HtmlReportRunner.java, report is being generated, but there is no record as a result of TestClass#test(){DevCode.someFunc(); } call. The report only contains unit tests coverage, which I have in Dev project.

What should I do here to make coverage.db contain also method calls from QE project?

I guess that instrumented codes get path of coverage.db from instrumentation.ser file located in jar.

below is the clover related config part of Dev project pom.xml. Am I missing any configuration?

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...